Events are caught/handled on the same thread from which they are raised. If you're doing work with the Windows message pump (aka, a GUI app) then you would need to marshal the thread to the so-called UI thread by using the Invoke or BeginInvoke method of any System.Windows.Forms.Control derived class. To test the need for this you can use the InvokeRequired property of any Control-derived class.
A pattern I use for methods which might be called from a non-Thread is this (this class is usually a form class, thus "this" is referring to a object derived from System.Windows.Forms.Form): private delegate void UpdateStatusLabelDelegate(string newText); private void UpdateStatusLabel(string newText) { if(this.InvokeRequired) { this.BeginInvoke(new UpdateStatusLabelDelegate(this.UpdateStatusLabel), new object[]{newText}); } else { this.statusTextBox.Text = newText; } } This way I can call this method from any thread and not have to "worry" what thread I'm calling it from as the method will marshall itself if required. You can find this in the SDK Docs. Regards, J. Vince Pacella / OOCL Chicago Cell 773-454-8683 Fax - 773-867-5050 Cargo Tracking Online at: www.cargosmart.com > -----Original Message----- > From: Unmoderated discussion of advanced .NET topics. > [mailto:[EMAIL PROTECTED] On Behalf Of > Stephen L. Bub > Sent: Wednesday, September 07, 2005 15:00 > To: ADVANCED-DOTNET@DISCUSS.DEVELOP.COM > Subject: [ADVANCED-DOTNET] Multi threading and events > > Hi, > > My name is Stephen. Could you please tell me whether events > are fired using the thread that raised the event, a new > thread, or a thread from the thread pool. For example, what > thread does a System.Timers.Timer Elapsed event run on. How > can I find this out for each class, etc. I am developing an > application using multiple serial communications ports and > timers, and this would help me determine whether I need to > use multi- threading. If new or pooled threads are used to > service events, then why would I need to use multi-threading? > Currently, when I call Thread.Sleep > (10000) on the thread in the user interface, the rest of the > application in seperate classes, using timers and > communication ports, keeps running. > > Yours truly, > > Stephen Bub > > =================================== > This list is hosted by DevelopMentor(r) http://www.develop.com > > View archives and manage your subscription(s) at > http://discuss.develop.com > > > IMPORTANT NOTICE Email from OOCL is confidential and may be legally privileged. If it is not intended for you, please delete it immediately unread. The internet cannot guarantee that this communication is free of viruses, interception or interference and anyone who communicates with us by email is taken to accept the risks in so doing. Without limitation, OOCL and its affiliates accept no liability whatsoever and howsoever arising in connection with the use of this email. Under no circumstances shall this email constitute a binding agreement to carry or for provision of carriage services by OOCL, which is subject to the availability of carrier's equipment and vessels and the terms and conditions of OOCL's standard bill of lading which is also available at http://www.oocl.com. =================================== This list is hosted by DevelopMentorĀ® http://www.develop.com View archives and manage your subscription(s) at http://discuss.develop.com