.NET invoking against an arbitrary control.
Posted
by
kerkeslager
on Stack Overflow
See other posts from Stack Overflow
or by kerkeslager
Published on 2011-03-10T15:37:06Z
Indexed on
2011/03/10
16:10 UTC
Read the original article
Hit count: 506
I have a method which takes in a .NET control and calls invoke against it like so:
Form.Invoke(Target);
However, I've run into an issue numerous times calling this method where due to timing or whatever, the form handle on the form doesn't exist, causing a Invoke or BeginInvoke cannot be called on a control until the window handle has been created
error. In frustration, I jokingly changed the code to:
MainForm.Invoke(Target);
where MainForm
is the main window of the application (the form handle for the main form is created at startup and remains active for the entire life cycle of the application). I ran all the tests and manually tested the application and everything seems to work fine despite the fact that this is used everywhere.
So my question is, what exactly is the meaning of invoking against a specific control? Is there any downside to just always invoking against a control you know will be active? If not, why does .NET have you invoke against a control in the first place (instead of just creating a static GuiThread.InvokeOnGuiThread(Blah);
)?
© Stack Overflow or respective owner