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 / December 2005

Tip: Looking for answers? Try searching our database.

Threading in .NET

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
sonali_reddy123@yahoo.com - 28 Dec 2005 13:44 GMT
Hi all,

I have a problem regarding the threading issues in .NET. Actually I
have a application in which i execute a process by invoking the thread
in the background and at the same time I
want to display a modal dialog which will only block my UI. It doesn't
have to do anything with my thread executing in the background.

Actually the dialog is getting displayed as result of the process
carried out by a thread in background. So the thread accepts the output
from the dialog and continues with furter
processing.

The problem is the dialog which I am displaying is not getting
displayed as a modal dialog.
And I don't want the user to interact with the background UI while the
dialog is getting displayed.

Is it that Calling ShowDialog from the thread event handler causing the
problem if so what is the solution.

Thanks in advance
Jon Shemitz - 28 Dec 2005 21:08 GMT
> Actually the dialog is getting displayed as result of the process
> carried out by a thread in background. So the thread accepts the output
[quoted text clipped - 8 lines]
> Is it that Calling ShowDialog from the thread event handler causing the
> problem if so what is the solution.

Hard to tell from your description what the problem is. General rule
is: You should only ever touch controls from the thread that creates
them. If you create the modal dialog in the main thread, you should
ShowDialog it from the main thread, using something like
MainForm.Invoke().

Signature

    <http://www.midnightbeach.com>

Tim_Mac - 28 Dec 2005 22:56 GMT
hi Sonali,
from your background thread, you should call a method using BeginInvoke to
transfer execution of that method to the main UI thread.  then you call
ShowDialog from that method and it will block the UI thread only, and the
modal function will work normally.
example below (untested):

private void MyAsyncMethod()
{
   // do stuff.. running on background thread
   // ...

   // ok, now want to ShowDialog on the main UI thread
   BeginInvoke(new MyDelegate(this.MethodForShowDialog), null, null);

   // the background thread will continue running asynchronously,
regardless of ShowDialog() on the main UI thread
}

delegate void MyDelegate();
private void MethodForShowDialog()
{
       // now running on UI thread
       MessageBox.ShowDialog(...whatever...);
}

is this what you want?
tim

--------------------------
blog: http://tim.mackey.ie 

Rate this thread:







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.