.NET EVents & Threading

G

Guest

Hi all


When .NET fires and event, does the event handler execute under a new
thread, or does it execute under the primary application thread?

Basically if I have events firing, do the event handlers themselves need to
spawn need threads, or can I safely assume the event handler is already
running under a new thread?

Thanks!
 
A

Armin Zingler

Spam Catcher said:
Hi all


When .NET fires and event, does the event handler execute under a
new thread, or does it execute under the primary application thread?

The event handler runs in the same thread as the code that raises the event.
No thread is created. The event handler is just a function called.
Basically if I have events firing, do the event handlers themselves
need to spawn need threads, or can I safely assume the event handler
is already running under a new thread?

If you want to run something in a new thread each time the event handler is
called, you must start the thread on you own.


Armin
 
G

Guest

The event handler runs in the same thread as the code that raises the
event. No thread is created. The event handler is just a function
called.


If you want to run something in a new thread each time the event
handler is called, you must start the thread on you own.

Thank you - That clears it up :)
 
T

Tom Shelton

The event handler runs in the same thread as the code that raises the event.
No thread is created. The event handler is just a function called.


If you want to run something in a new thread each time the event handler is
called, you must start the thread on you own.

Armin


Or run the delegate asycronously using BeginInvoke - in that case, the
method will be called on a thread from the thread pool.
 
G

Guest

Or run the delegate asycronously using BeginInvoke - in that case, the
method will be called on a thread from the thread pool.

If I do so, I'll have to call EndInvoke correct?

I'm using Threadpool.QueueUserWorkItem to process each call in it's own
thread.
 

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

Similar Threads


Top