Avoid calling Invoke when the control is disposed

后端 未结 14 1441
花落未央
花落未央 2020-12-01 16:09

I have the following code in my worker thread (ImageListView below is derived from Control):

if (mImageListView != null &&          


        
14条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-01 16:24

    One way might be to call the method itself ones more instead of invoking the ImageListView-Method:

    if (mImageListView != null && 
        mImageListView.IsHandleCreated &&
        !mImageListView.IsDisposed)
    {
        if (mImageListView.InvokeRequired)
            mImageListView.Invoke(new YourDelegate(thisMethod));
        else
            mImageListView.RefreshInternal();
    }
    

    That way it would check one more time before finally calling RefreshInternal().

提交回复
热议问题