Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / October 2004

Tip: Looking for answers? Try searching our database.

How to show a modal dialog from a different thread

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Faris Ahmed - 15 Oct 2004 16:53 GMT
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
Cole - 15 Oct 2004 17:11 GMT
> 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
Herfried K. Wagner [MVP] - 15 Oct 2004 17:27 GMT
"Faris Ahmed" <Faris Ahmed@discussions.microsoft.com> schrieb:
> 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/en-us/cpref/html/frlrfSystemWindowsFormsContro
lClassInvokeTopic.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>

Signature

Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/

Stoitcho Goutsev \(100\) [C# MVP] - 16 Oct 2004 15:49 GMT
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.

--
HTH
Stoitcho Goutsev (100) [C# MVP]

> Hi,
> I have the following classical situation;
[quoted text clipped - 19 lines]
> Regards,
> Faris

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.