Threading problem with MDI form

P

Paul Shave

In an MDI app, from a child form I use BeginInvoke on a delegate to
start an async printing process. When it finishes, my callback
function (on the worker thread) calls me.BeginInvoke to get back to
the main thread where I update the status line on the MDI form
(Printing complete). This works fine, but the problem is that if the
user closes the child form before the printing is complete, the
callback executes but the main thread has now gone, so the MDI form
status bar doesn't get updated.

The worker thread at this point doesn't have an MdiParent. How can I
get back to the MDI form from the worker thread callback function to
update the status line?

Paul Shave
 
A

AlexS

Maybe you should pass reference of updated control to worker thread
callback? I would do that.

HTH
Alex
 
P

Paul Shave

Maybe you should pass reference of updated control to worker thread
callback? I would do that.

The problem is that (because forms' controls are not thread-safe) you
are forbidden from updating a form's control from the worker thread -
you have to get back on to the main thread.

Paul
 
A

AlexS

That's what for Invoke methods are.

HTH
Alex

Paul Shave said:
...

The problem is that (because forms' controls are not thread-safe) you
are forbidden from updating a form's control from the worker thread -
you have to get back on to the main thread.

Paul
 
P

Paul Shave

That's what for Invoke methods are.
But you can't do a Me.Invoke to get back to the main thread because
the child window's closed so there isn't one any more.

Paul
 

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