Detect if control was disposed

In my application I have a user control that do async operations using thread pool. The thread pool method looks like:

private void AsyncFunction(object state)
    {
        ... do the calculation
        //refresh the grid data on the UI thread
        this.BeginInvoke(new MethodInvoker(() =>
                                               {
                          ... update the ui 
                                               }));
    }

My problem is that if the user closes the dialog ... the user control gets disposed and I get the exception:

Invoke or BeginInvoke cannot be called on a control until the window handle has been created.

Do you know a way to detect if the dialog was disposed? I don't want to hae a property on control that the dialog set when closed. Is there another way of solving this?

Thanks,

Radu

14
задан Radu D 16 December 2010 в 12:23
поделиться