Weirdly I haven't been able to find an answer in the doc or on the web although it seems to be a simple question:
Imagine I registered to a c# event in a conditional block:
void Execute()
{
if(loader.AlreadyCompleted)
{
DoSomething();
}
else
{
loader.Completed += DoSomething;
}
}
In this example, a loader will trigger the Completed event. If it already happended AlreadyCompleted will be true, otherwise it is false and I want to register to the Completed event in order to wait before executing DoSomething.
Now imagine that I have an Abort function that could be trigger anytime.
In the Abort function I will need to deregister from the Completed event.
void Abort()
{
loader.Completed -= DoSomething;
}
What will happen if the loader was ready at startup and we never executed the line loader.Completed += DoSomething; ? Can we deregister an event that hasn't been registered? Is there a way to check if we are registered? What's the best practice in this case?