If I create a lambda callback such as this:
var someInstance = new SomeObject();
someInstance.Finished += (obj, args) =>
{
// Do something
// Deregister here
};
someInstance.DoAction();
How could I deregister the callback as part of the actual handler code? This pattern would be ideal as I could ensure it is released as soon as possible.
I've seen similar questions but not one where this type of example is directly addressed.
With something like,
var someInstance = new SomeObject();
EventHandler myDelegate = null;
myDelegate = (obj, args) =>
{
// Do something
// Deregister here
someInstance.Finished -= myDelegate;
};
someInstance.Finished += myDelegate;
someInstance.DoAction();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With