473,387 Members | 1,493 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

.NET EVents & Threading

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!
Feb 21 '07 #1
5 1265
"Spam Catcher" <sp**********@rogers.comschrieb
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

Feb 21 '07 #2
"Armin Zingler" <az*******@freenet.dewrote in
news:ui**************@TK2MSFTNGP04.phx.gbl:
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.
Thank you - That clears it up :-)
Feb 21 '07 #3
On Feb 21, 2:36 pm, "Armin Zingler" <az.nos...@freenet.dewrote:
"Spam Catcher" <spamhoney...@rogers.comschrieb
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

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

--
Tom Shelton

Feb 21 '07 #4
"Tom Shelton" <to*********@comcast.netwrote in
news:11**********************@q2g2000cwa.googlegro ups.com:
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.
Feb 21 '07 #5
On 2007-02-21, Spam Catcher <sp**********@rogers.comwrote:
"Tom Shelton" <to*********@comcast.netwrote in
news:11**********************@q2g2000cwa.googlegro ups.com:
>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?
Yes - you should call endinvoke.

--
Tom Shelton
Feb 22 '07 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Bardo | last post by:
Hi, I have a situation where I am capturing both a WMI event utilising the "ManagementEventWatcher" in the "System.Management" namespace, and a corresponding event ("EntryWritten") raised from...
2
by: Gulshan Oshan | last post by:
I want to implement a simple console that continuously listens for an event from a custom object. I am unable to capture the events from the object. If I subscribe to the events in a windows app...
2
by: elziko | last post by:
I have an object (Object1) that instantiates another class (Object2) in a seperate thread. It must be in its own thread for an ActiveX control it hosts to work. From Object1 I can get to all the...
3
by: Chris Dunaway | last post by:
Consider the following simple classes/interfaces defined below. When the derived class raises the events, on which thread is the event code run? Do I need to do anything to catch the events in my...
13
by: Bob | last post by:
My WinForms app runs on the single default thread, and uses a single SqlConnection object for all queries. I need to use one or more timers to periodically execute some of them. My own testing...
3
by: daan | last post by:
Hello, I have a problem and I can't get the solution for it :( I have a com dll, which i imported as a reference. The com object is part of a class which is multithreaded and will create...
3
by: Hardy Wang | last post by:
Hi all, I am migrating a Windows Form application from .Net 1.1 to 2.0. I try to use BackgroundWorker object to handle a very lengthy process. I have a separated class to handle some very complex...
12
by: Aidal | last post by:
Hi NG. I'm creating a little app. that has to use a 3rd party API. The functions in this API has no return value but trigger events like OK or NOT OK with event args. Where I need to use this...
5
by: JasonX | last post by:
Im having problems with my program, in that if I close the main form while my new thread is doing work which involves writing to the main form, then I get an error about a disposed object. To...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.