Click here to Skip to main content
15,891,513 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi I have an application that hs been written with C#

and it has a class that it contains a function(timer with this arguments object sender, EventArgs e) and now

I want to call this function by another class thus i create an instance of this class
when i call this function with timer_Tick(null , eventargs.empty )
or (object sender ,eventargs.empty )

for arguments "object sender , event args e"
error has occured?


anybody have a solution?
thanks
Posted
Updated 2-Sep-11 22:28pm
v2
Comments
Oshtri Deka 3-Sep-11 4:48am    
Give us some code to see what exactly you had in mind.

Don't call such functions directly: they are Event handlers and should be called by the framework at the appropriate time.
Instead, create a private method which you call, and which the event handler calls.

That way you do not need to provide the sender or EventArgs. However, there is no EventArgs.Empty anyway!

Be aware though that what you are trying to do it probably wrong, and may be dangerous later, when you learn about threading.

I suspect that you actually want to create an event in one class, and subscribe to it in the other - but I don't know what you are trying to achieve, so I can't advise you how to do it.


[edit]Removed error: there is indeed an EventArgs.Empty (thanks GParkings) - OriginalGriff[/edit]
 
Share this answer
 
v2
Comments
GParkings 3-Sep-11 6:50am    
griff is correct in that you should reconsider code design so as to not explicitly call event handlers. (the assumption here is that by function you mean the event handler method and not an instance of Func<t>)

EventArgs.Empty does exist, however : http://msdn.microsoft.com/en-us/library/system.eventargs.empty.aspx
OriginalGriff 3-Sep-11 6:53am    
I stand corrected! Thank you - I'll give you a five next time I see somewhere I can... :)
instead of directly calling such function create one event using delegate and call in appropriate time
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900