I'm trying to fill a knowledge gap. I have a control that calls BeginInvoke(delegate), then afterward the control immediately disposes itself.
The delegate never seems to occur. It would seem to be a result of the Control.Dispose().
My confusion lies in the fact that (I thought) BeginInvoke places the delegate onto the Windows Message Queue to be processed later on the UI thread. Why would disposing the control have anything to do with this delegate no longer firing? It was already placed on the queue before disposing.
Also, if it has something to do with the Windows Handle, why do I not get an Exception instead of a quiet ignore of the delegate?
below is a simple example of what I mean:
class myControl : UserControl
{
public myControl()
: base()
{ }
public void DoBeginInvoke()
{
this.BeginInvoke(new MethodInvoker(
() => { Console.WriteLine("!!TESTING 123!!"); }
));
// silently prevents the delegate from occuring..
this.Dispose();
}
}
Thanks in advance for your explanation. Apologies for the simplistic question.