ObjectDisposedException with Contol.Invoke

  • Thread starter George Chatzigeorgiou
  • Start date
G

George Chatzigeorgiou

Hello all.

On a winforms aplication for the compact framework, I get this strange
error. The first time the form is constructed, everything is ok. The
second time, I get this exception when trying to use Control.Invoke on a
control. The code looks something like this

void ShowUpdateForm()
{
frmUpdate fup = new frmUpdate();
fup.ShowDialog();
//fup.Dispose();

}

As I said, the first time ShowUpdateForm is called, everything is ok.
If I try to call it once more then every Control.Invoke funtion in the
form, gives a ObjectDisposedException. I tried disposing the form after
show dialog (code in comments) but to no avail.

Any help would be appreciated.
Thanks
 
D

Daniel Moth

First, the only controlinvoke + showdialog issue I am aware of was resolved
with SP1 so check you have the latest version installed.
Second, uncomment the call that disposes the form. You should do this for
forms you display with ShowDialog.

You have to show us the code in frmUpdate. Without seeing your Invoke calls
we are just guessing. If it is large, post a small repro.

On the guessing front, maybe somewhere you are caching the reference to the
frmUpdate instance (maybe in the calling form, maybe in a static variable on
frmUpdate, maybe by passing it to some other class that persists etc). So
later you are attempting to control.invoke on that instance which is already
disposed.

To try to debug the problem, the first step would be to put a breakpoint on
all the <control>.Invoke statements (since you assert that is where the
problem lies) and identify which one causes the issue. Then debug again,
this time examining the state of all instances in scope before the exception
is thrown...

Cheers
Daniel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top