event in thread

  • Thread starter Thread starter Gary Brewer
  • Start date Start date
G

Gary Brewer

Hello,

In a windows form, if I am doing some work in a thread and I wire an event
handler up to change something in the UI, can I create the event handler
link up in my thread or do I have to create a delegate and invoke it on my
windows form thread for it to work properly?

Gary Brewer
 
Hello Gary,

You should use the System.Windows.Forms.Control.Invoke method to access any
UI-related properties or methods from another threads.
 
Ok,

So sweeping statement of the day is -

Events wired in a thread will execute on that thread if raised.







Dmitriy Lapshin said:
Hello Gary,

You should use the System.Windows.Forms.Control.Invoke method to access any
UI-related properties or methods from another threads.

--
Dmitriy Lapshin [C# / .NET MVP]
X-Unity Test Studio
http://x-unity.miik.com.ua/teststudio.aspx
Bring the power of unit testing to VS .NET IDE

Gary Brewer said:
Hello,

In a windows form, if I am doing some work in a thread and I wire an event
handler up to change something in the UI, can I create the event handler
link up in my thread or do I have to create a delegate and invoke it on my
windows form thread for it to work properly?

Gary Brewer
 
Hi,

I use events from threads (often, though not universally).

The event code is executed in the worker-thread context. The implication of
this is that any manipulation of Form (STAThread) objects, should use
Control.Invoke or Control.BeginInvoke to properly marshal data between the
respective threads.

Dick

--
Richard Grier (Microsoft Visual Basic MVP)

See www.hardandsoftware.net for contact information.

Author of Visual Basic Programmer's Guide to Serial Communications, 3rd
Edition ISBN 1-890422-27-4 (391 pages) published February 2002.
 
Back
Top