Avoid calling Invoke when the control is disposed

What you have here is a race condition. You’re better off just catching the ObjectDisposed exception and be done with it. In fact, I think in this case it is the only working solution.

try
{
    if (mImageListView.InvokeRequired)
       mImageListView.Invoke(new YourDelegate(thisMethod));
    else
       mImageListView.RefreshInternal();
} 
catch (ObjectDisposedException ex)
{
    // Do something clever
}

Leave a Comment