C# UserControl BeginInvoke Problem
I have got a C# user control, which has got it's own background worker thread. This worker thread is started in the constructor of the control and stopped when the control is disposed.
The thread periodically calls the BeginInvoke-Method with a开发者_如何学Python delegate, but sometimes the exception "Invoke or BeginInvoke cannot be called on a control until the window handle has been created." occoures.
Now I ask you, how can I check whether calling BeginInvoke is possible from my worker thread to do no invoking as long as the control isn't completely created?
This problem only occoures when compiling a release. Not in debug mode.
with best regards
The worker thread should be created inside... (you have two options):
- A handler of Control.HandleCreated event
- Overriding Control.OnHandleCreated
What you need to know is that a control may not be fully created (ready to be used) even after the constructor is done executing.
精彩评论