473,385 Members | 1,620 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,385 software developers and data experts.

Raising events cross threads

I have a component class that has a set of events. The class
uses a worker thread to do some processing. When it is
finished with the processing, it raises the appropriate
events.

Problem, since these events are being raised in the worker
thread, the clients connected to the events are receiving
notification outside of the thread in which they belong.

Is there a way to raise events in such as way as to
guarantee that the notification is sent to the proper
thread?
Nov 16 '05 #1
2 3450
when you say componentm as you talking about a visual component or just a
class you have written (unfortunately its a overloaded term).

If visual you can call Control.BeginInvoke that will marshal the call to the
UI thread.

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

"Wavemaker" <ja**********@BiteMeHotmail.com> wrote in message
news:W6********************@comcast.com...
I have a component class that has a set of events. The class
uses a worker thread to do some processing. When it is
finished with the processing, it raises the appropriate
events.

Problem, since these events are being raised in the worker
thread, the clients connected to the events are receiving
notification outside of the thread in which they belong.

Is there a way to raise events in such as way as to
guarantee that the notification is sent to the proper
thread?

Nov 16 '05 #2

"Richard Blewett" wrote:
when you say componentm as you talking about a
visual component or just a class you have written
(unfortunately its a overloaded term).
The class derives from System.ComponentModel.Component.
If visual you can call Control.BeginInvoke that will
marshal the call to the UI thread.


Unfortunately, the Component class doesn't have the
BeginInvoke method, which makes sense, I suppose, but I
would sure find it handy in the situation I'm in. :-)

Doing some research on this since posting, it seems the best
course of action for me is to document thoroughly that the
events raised by my component are in their own thread so
that listeners can respond appropriately. For example, a
Form would test the InvokeRequired property and use the
BeginInvoke method if necessary.
Nov 16 '05 #3

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

Similar topics

28
by: Dennis Owens | last post by:
I am trying to run a thread off of a form, and every once in a while the thread will raise an event for the form to read. When the form gets the event, the form will place the event into a dataset...
4
by: Chris | last post by:
Hi, I followed the the aricle http://support.microsoft.com/default.aspx?scid=kb;en-us;321525 and was able to execute a dts package in vb.net. I replaced all the "Console.WriteLine" with "msgbox"....
3
by: James Dunkerley | last post by:
Hi, I am trying to create a class which downloads a web page in the background and then raises an event in the original thread in which it was created. This class is going to be the basis of a...
6
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a...
15
by: Bryce K. Nielsen | last post by:
I have an object that starts a thread to do a "process". One of the steps inside this thread launches 12 other threads via a Delegate.BeginInvoke to process. After these 12 threads are launched,...
0
by: Apu Nahasapeemapetilon | last post by:
Suggestions on cross-posting this issue would be appreciated. I've got a C# .NET DLL (CLR v1.1) that raises events into its container. When the container is a .NET application, raising the...
9
by: CuriousGeorge | last post by:
Can someone explain why this code DOES NOT raise a null reference exception? //////////////////////////// Program.cs ///////////////////////////////////////////// using System; using...
23
by: Thomas Due | last post by:
Hi, I have a class which monitors a TCP socket. This will on occasion raise an event which can be handled by a GUI. Now, I am aware of the if(InvokeRequire) { EventHandler d = new...
3
by: =?Utf-8?B?THVib21pcg==?= | last post by:
Hi, I have an app with the main thread and one additional thread. In the main thread I defined an event handler MyHandler, the function for raisin this event OnMyEvent and the function for...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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.