开发者

Invoke handle error on close despite multiple sanity checks

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?


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.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜