By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,052 Members | 1,551 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,052 IT Pros & Developers. It's quick & easy.

Events And Multiple Threads

P: n/a
I'm looking to understand the way events work across multiple threads. I have an object that needs to process data as it comes in. When a certain threshold is hit, it needs to tell the host application via an event. If the app is running on Thread A and the process inside the data processing object is running on Thread B, which thread runs the event handler? What's blocked and in what order? Thanks.

Jerry
Sep 28 '06 #1
Share this Question
Share on Google+
4 Replies


P: n/a
Jerry,

Event handlers are executed on the thread that fires the events. So if
you do something to fire an event, all of the event handlers are going to
execute on that thread.

Hope this helps.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

<rl*****@newsgroups.nospamwrote in message
news:uA**************@TK2MSFTNGP02.phx.gbl...
I'm looking to understand the way events work across multiple threads. I
have an object that needs to process data as it comes in. When a certain
threshold is hit, it needs to tell the host application via an event. If
the app is running on Thread A and the process inside the data processing
object is running on Thread B, which thread runs the event handler? What's
blocked and in what order? Thanks.

Jerry
Sep 28 '06 #2

P: n/a
<rl*****@newsgroups.nospamwrote
I'm looking to understand the way events work across multiple threads.
There's a real simple answer to that: Events don't cross threads. Any
registered handlers will run on the thread that raised the event.

--
Chris Mullins, MCSD.NET, MCPD:Enterprise
http://www.coversant.net/blogs/cmullins
Sep 28 '06 #3

P: n/a
Thanks guys.
<rl*****@newsgroups.nospamwrote in message news:uA**************@TK2MSFTNGP02.phx.gbl...
I'm looking to understand the way events work across multiple threads. I have an object that needs to process data as it comes in. When a certain threshold is hit, it needs to tell the host application via an event. If the app is running on Thread A and the process inside the data processing object is running on Thread B, which thread runs the event handler? What's blocked and in what order? Thanks.

Jerry
Sep 28 '06 #4

P: n/a
Hi Jerry,

In addition to all other community's correct replies, if you are
programming .Net winform, I want to share another information to you.

Since winform controls are using STA threading model, if a worker(non-GUI)
thread fired an event, this event will execute in this non-GUI thread, any
accessing to the GUI control methods/properties must be marshaled with
Control.Invoke method(see this method in MSDN) to keep thread-safe. This is
Net winform multithreading programming rule and is prone to programming
error.

Please refer to "Wrapping Control.Invoke" section in the article below for
more information:
http://msdn.microsoft.com/msdnmag/is...ultithreading/

Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Sep 29 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.