By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,056 Members | 1,320 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,056 IT Pros & Developers. It's quick & easy.

Detach an event based on an anonymous method?

P: n/a
Hi, is it possible to detach an event which is implemented via an anonymous
method.

ie. If the code is:
myObject.myEvent += delegate(object sender, EventArgs e) {
// snip event actions
}

is there a way that I can I detach this later via -=, or do I need to use a
named event?

thanks
Barry Mossman
Sep 24 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Barry,
>Hi, is it possible to detach an event which is implemented via an anonymous
method.
Only if you keep a reference to the delegate.

EventHandler x = delegate(object sender, EventArgs e) {
// snip event actions
}
myObject.myEvent += x;
....
myObject.myEvent -= x;
Mattias

--
Mattias Sjögren [C# MVP] mattias @ mvps.org
http://www.msjogren.net/dotnet/ | http://www.dotnetinterop.com
Please reply only to the newsgroup.
Sep 24 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.