MessageBox (or equiv) while background thread completing long operation.

  • Thread starter Thread starter Lloyd
  • Start date Start date
L

Lloyd

I have a windows forms application (.net 1.1) and I want to have a msgbox
like window blocking the main thread while a long operation completes in a
background thread. Is there a way to do this using MessageBox.Show() and
somehow closing it from the other thread? Or will I need to make a basic
form and have an event on it to do a this.close() from the other thread?
Something entirely different?

Sorry if this is a repeat, the terms are fairly ambiguous so I couldn't
google much.

Lloyd Christopher
SLOW30
 
From the user point of view, It seems the MessageBox.Show method is not
appropriate in most cases. A dialog with label, progress bar, and maybe
a Cancel buttuon would be better. However, no matter what kind of modal
dialog you use, just start your background thread, show the modal
dialog. Note that if you want to update the dialog (e.g. progress
status) or close it from the background thread, don't call the
corresponding methods directly. Instead, use Control.Invoke or
BeginInvoke function to ensure the methods are called by the thread
that created the control.
 
If you want to block the main thread, then why not just perform your
operation on the UI thread?

Seems like there wouldn't be any difference...
 
Hi Lloyd,

Then I'd agree with Truong... I'd say use a small dialog and then create the
thread and then remove the dialog once the thread is complete, _or_ disable
your form, create and start the thread and then do something like --

do
{
Application.DoEvents();
} while(bgThreadRunning);

That would keep the UI refreshed...
 
Back
Top