Hey,
Normally when you are using events and you add a delegate you can easily unsubscribe when cleaning up the object (on a side question if you dont will it not be GCed until it is?).
However when you use anon methods (not sure if my syntax is 100% but you get the idea:Code:// Subscribe SomeObject.SomeEvent += SomeObject_SomeEvent; void SomeObject_SomeEvent(object sender, EventArgs e) { Console.WriteLine("Called Some Event"); // Unsubscribe (could cast sender) SomeObject.SomeEvent -= SomeObject_SomeEvent; }
You cant seem to unsubscribe (or there is no simple way that stands out to me) so im wondering how you can remove the listener, as i basically want to have an objects event to be listened out for once then trigger something else and then stop listening...Code:// Subscribe SomeObject.SomeEvent += new delegate(object sender, EventArgs e) { Console.WriteLine("Called Some Event"); // How do i unsubscribe? }




Reply With Quote