473,396 Members | 2,011 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,396 software developers and data experts.

Events in a .NET thread

Tom
First of all, is it 'legal' (i.e. thread-safe) to pass events back from
a worker thread to the main thread? I.E. Can one put PUBLIC EVENT XYZ
in their worker thread and then raise that event for processing back in
the main thread? I believe this is OK, but I want to check first...

Secondly, if this is 'legal', what happens in the following scenario:
Lets say that in my main (Win Form) program/thread I spawn two worker
threads. Thread one does some work then raises the 'ImAlmostDone' event
back to my main thread. Now, at about the same time, my second thread
also raises a 'ImAlmostDone' event back. In this case, do both events
get processed in the main thread? And do they get processed in the
proper order - i.e. thread 1's event, then thread 2. Or do I need to do
any thread locking before I process the event (i.e. to make sure the
main thread finishes the event before the next thread raises the same
event)

Before I start passing events back, I want to make sure this is going
to work and I am not going to screw things up.

Thanks in advance.

Tom
Nov 21 '05 #1
1 1210
A thread that raises an event handles the event. So in this case, your
threads will handle the events and not your main thread. If you want the
form's thread to handle the events for you, you should use Me.Invoke or
Me.BeginInvoke to call a delegate.
"Tom" <to*@nospam.com> wrote in message
news:uM**************@TK2MSFTNGP10.phx.gbl...
First of all, is it 'legal' (i.e. thread-safe) to pass events back from
a worker thread to the main thread? I.E. Can one put PUBLIC EVENT XYZ
in their worker thread and then raise that event for processing back in
the main thread? I believe this is OK, but I want to check first...

Secondly, if this is 'legal', what happens in the following scenario:
Lets say that in my main (Win Form) program/thread I spawn two worker
threads. Thread one does some work then raises the 'ImAlmostDone' event
back to my main thread. Now, at about the same time, my second thread
also raises a 'ImAlmostDone' event back. In this case, do both events
get processed in the main thread? And do they get processed in the
proper order - i.e. thread 1's event, then thread 2. Or do I need to do
any thread locking before I process the event (i.e. to make sure the
main thread finishes the event before the next thread raises the same
event)

Before I start passing events back, I want to make sure this is going
to work and I am not going to screw things up.

Thanks in advance.

Tom

Nov 21 '05 #2

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

Similar topics

0
by: Steven Brown | last post by:
I'm trying to figure out how to safely use .NET events/delegates in a thread-safe class. There are a couple problems. One is that the standard "if(EventName != null) EventName(...);" call can...
10
by: Drakier Dominaeus | last post by:
This is my first time posting here, so please forgive me if I do anything incorrectly. I've been learning C# and working with different things and decided I wanted to get into Multi-Threading....
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...
3
by: Jacob | last post by:
I'm working on a class that needs to be called from a windows form, do it's work, and then, show progress back to the main form. I'm well aware that worker threads need to call Invoke for updates...
3
by: Stampede | last post by:
Hi, I want to use the FileSystemWatcher in a Windows Service. I read an article, where the author created the FileSystemWatcher object in a seperate thread and when the event is fired, he started...
12
by: scsharma | last post by:
Hi, I am working on creating a webapplication and my design calls for creating main webform which will have menu bar on left hand side and a IFrame which will contain all the forms that are shown...
14
by: Gotch | last post by:
Hi all, I've recently digged into C# and the whole .Net stuff. Particularly I found the idea of adding Events and Delegates to the C# language very interesting and I'm trying to use them in...
4
by: jehugaleahsa | last post by:
Hello: Is there a way to prevent one event from firing while another event is already being fired? I have a tool that extracts media from web pages and it has multiple events firing when the...
15
by: damiensawyer | last post by:
Hi, I am creating a class (from a base class) that needs to trigger events (code at bottom). I am instatiating the classes and wiring up the events as follows. clsDetermineConnection oDC =...
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: 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: 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
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
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.