尽管进行了多次健全性检查,但在关闭时调用句柄错误
我正在使用这个小实用程序函数:
public static void Invoke(Control control, Action method)
{
if (control.InvokeRequired)
{
if (control.IsDisposed || !control.IsHandleCreated || !control.Created)
return;
control.Invoke(method);
}
else
method();
}
尽管进行了所有这些健全性检查,当我关闭应用程序时,杂散调用总是会产生此错误:
Invoke or BeginInvoke cannot be called on a control until the window handle has been created.
尽管显然有一个检查来查看句柄是否已创建...还有什么我可以做什么吗?
I'm using this small utility function:
public static void Invoke(Control control, Action method)
{
if (control.InvokeRequired)
{
if (control.IsDisposed || !control.IsHandleCreated || !control.Created)
return;
control.Invoke(method);
}
else
method();
}
Despite all of those sanity checks, when I close my application, a stray invoke always produces this error:
Invoke or BeginInvoke cannot be called on a control until the window handle has been created.
This, despite there clearly being a check to see if the handle is created... What else can I do?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
仔细阅读此主题其中深入研究了调用。您遇到的问题几乎可以肯定是由于 if(...) 返回之间的控件消失了; Invoke 正在做它的事情。
Read through this thread which delves into Invoke'ing. The problem you're experiencing is almost certainly down to a control disappearing between the if(...) return; and the Invoke doing its thing.