C# UserControl BeginInvoke 问题
我有一个 C# 用户控件,它有自己的后台工作线程。该工作线程在控件的构造函数中启动,并在控件被释放时停止。
线程定期使用委托调用 BeginInvoke 方法,但有时会出现异常“在创建窗口句柄之前无法在控件上调用 Invoke 或 BeginInvoke。”。
现在我问你,如何检查我的工作线程是否可以调用BeginInvoke,只要控件没有完全创建就不会调用?
仅在编译版本时才会出现此问题。不在调试模式下。
最诚挚的问候
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 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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
工作线程应该在内部创建...(您有两个选择):
您需要知道的是,即使在之后,控件也可能尚未完全创建(准备使用)构造函数执行完毕。
The worker thread should be created inside... (you have two options):
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.