Link to home
Start Free TrialLog in
Avatar of gerry99
gerry99

asked on

How to avoid BeginInvoke before a handle has been created

Invoke or BeginInvoke cannot be called on a control until the window handle has been created.

This message bugs me.  

To avoid cross threading exceptions in my application I use BeginInvoke to update the StatusBar of my application.  The thread that updates the status bar does not know if it has been given a window handle yet, and checking for the existence of a handle tosses an exception.  If you write directly to a control, before it has a handle, no problem.  It is only when using method invocation that the window handle is necessary.

Does anyone have a design pattern to avoid this problem?

Thanks,
Gerry
ASKER CERTIFIED SOLUTION
Avatar of AlexFM
AlexFM

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of oobayly
Thanks for the points. I had seen that property but had (wrongly) assumed that it wouldn't be set to false when the handle was destroyed. The documentation says that it returns true if CreateHandle has been called, but makes no mention of it being Destroyed.

Just shows, test the code rather than relying on the documentation :-)
Damn, wrong thread.