event in thread

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
 
D

Dmitriy Lapshin [C# / .NET MVP]

Hello Gary,

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

Gary Brewer

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
 
D

Dick Grier

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top