开发者

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):

  1. A handler of Control.HandleCreated event
  2. 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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜