Jump to content
  • Advertisement
Sign in to follow this  
DrGUI

[.net] Event 'sender' when raised from static method

This topic is 4748 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi When you raise an event, you know you're meant to pass 'this' as the 'sender' parameter, but what do you do if you raise the event from a static function? Seems the only thing you can do really is pass null...

Share this post


Link to post
Share on other sites
Advertisement
Afraid not (Find in page hehe) but thanks for the link anyway.

DOn't worry people as I'm not using that event anymore [grin]

Share this post


Link to post
Share on other sites
Quote:
If the method to be invoked is a static method then this field will be null.


That's what I saw.

[Edited by - Daniel Miller on July 18, 2005 2:49:07 PM]

Share this post


Link to post
Share on other sites
As the 'raiser' of the event you're free to mark anything as the sender.
It might be an option to pass a Type object containing info on the class that raised the event... (Note I said 'might') Use typeof(...) to create such an object.

Otherwise null is acceptable.

Cheers

Share this post


Link to post
Share on other sites
Can I call you Dan?...that was talking about the members of single cast delegates. Perhaps I should have made it clearer that I meant:

you have your event...
public System.EventHandler MyLovelyEvent;

then you raise it...
if (MyLovelyEvent != null)
MyLovelyEvent(this, System.EventArgs.Empty);

However, when raising an event from a static function, you can't use 'this'.

Like ernow says, I would now use null. I was asking because I thought it might be bad practise to pass null :)

If you're interested - I changed from a event to an array of WeakReferences so it referenced objects could be GCed [smile]

Thanks for the replies!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!