How to show a modal dialog from a different thread

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,
I have the following classical situation;
1)A long operation needs to be done in my application( that has many windows )
2)A progress dialog must be shown in a separate thread
3)The long operation continues in the program main thread.

The problem is,
from the second thread I call ShowDialog(), but this dialog will not be
Modal!!!
Obviously .net modal dialog will only work if all dialogs in the application
are opened in same thread.

in my scenario I can simply switch between two dialogs( the progress dialog
and the backgroud dialog)

How can I show a dialog that is modal to all other dialogs even if the
application dialogs were opened in different threads?

Regards,
Faris
 
1)A long operation needs to be done in my application( that has many
windows )
Can you use delegates invoked async to do the *work* and then when they
return to main thread show your windows appropriately?

Cole
 
Faris Ahmed said:
I have the following classical situation;
1)A long operation needs to be done in my application
( that has many windows )
2)A progress dialog must be shown in a separate thread
3)The long operation continues in the program main thread.

Always show your forms in the app's main UI thread and use 'Control.Invoke'
to communicate in the tread -> UI direction:

Multithreading:

<URL:http://msdn.microsoft.com/library/en-us/dnforms/html/winforms06112002.asp>
<URL:http://msdn.microsoft.com/library/en-us/dnforms/html/winforms08162002.asp>
<URL:http://msdn.microsoft.com/library/en-us/dnforms/html/winforms01232003.asp>

<URL:http://www.devx.com/dotnet/Article/11358/>

<URL:http://msdn.microsoft.com/library/e...SystemWindowsFormsControlClassInvokeTopic.asp>

Multithreading in Visual Basic .NET (Visual Basic Language Concepts)
<URL:http://msdn.microsoft.com/library/en-us/vbcn7/html/vaconthreadinginvisualbasic.asp>

Sample:

<URL:http://dotnet.mvps.org/dotnet/samples/filesystem/downloads/FileSystemEnumerator.zip>
 
Hi Faris,

What you need to do is to do it the other way around. Show the dialog from
the UI thread and do the job from a worker thread. Otherwise AFAIK there is
no such a thing as process-modal dialog.
 
Back
Top