473,549 Members | 2,531 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

firing events between threads

Hello:

I need to fire events between two threads. Any suggestions on the best way
to accomplish this. Scenerio:

Thread A is main thread. Thread B is a Com port listener that fires an
event when it receives input. I need to fire this event to Thread A yet
allow thread B to continue processing while thread A handles the event. I
have looked at using the Messaging classes but this looks like overkill to
accomplish this.

Any suggestions are greatly appreciated.

Thanks

Bob
Nov 16 '05 #1
3 10073
Bob Lazarchik <bo*****@sditam pa.com> wrote:
I need to fire events between two threads. Any suggestions on the best way
to accomplish this. Scenerio:

Thread A is main thread. Thread B is a Com port listener that fires an
event when it receives input. I need to fire this event to Thread A yet
allow thread B to continue processing while thread A handles the event. I
have looked at using the Messaging classes but this looks like overkill to
accomplish this.

Any suggestions are greatly appreciated.


When you say Thread A is the "main" thread, what exactly do you mean?
What else is it doing? Unless it's running some sort of message pump
(or the like - a queue of jobs or whatever) then you're out of luck -
you can't just interrupt a thread and tell it to do something
different.

You could use a different thread entirely, of course, or the
threadpool.

--
Jon Skeet - <sk***@pobox.co m>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #2
Hi Bob,

If you are working on a Win app this is a piece of cake, you can use
Control.Invoke to have a delegate processed on the thread owning the
control, as your "main thread" should be the UI thread, where you declare
the controls then you get what you need.

Cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"Bob Lazarchik" <bo*****@sditam pa.com> wrote in message
news:ev******** ******@TK2MSFTN GP11.phx.gbl...
Hello:

I need to fire events between two threads. Any suggestions on the best way to accomplish this. Scenerio:

Thread A is main thread. Thread B is a Com port listener that fires an
event when it receives input. I need to fire this event to Thread A yet
allow thread B to continue processing while thread A handles the event. I
have looked at using the Messaging classes but this looks like overkill to
accomplish this.

Any suggestions are greatly appreciated.

Thanks

Bob

Nov 16 '05 #3
Does the event code _have_ to run in Thread A, or do you just not want for
it to block thread B? If the former, you are going to have to come up with
some way to interrupt Thread A.

If the latter, you can just use another thread, or you can implicitly use
another thread by using the BeginInvoke capability of the delegate (causes
an event to be fired asynchronously) .
Example (something like this, I haven't tried compiling):
Instead of this:
(Thread B firing the event):
if(this.MyEvent != null)
this.MyEvent(th eParams)

You could do something like this (syntax might be off)
// this causes the event handler code to execute on a 3rd thread
if(this.MyEvent != null)
this.MyEvent.Be ginInvoke(thePa rams);
"Bob Lazarchik" <bo*****@sditam pa.com> wrote in message
news:ev******** ******@TK2MSFTN GP11.phx.gbl...
Hello:

I need to fire events between two threads. Any suggestions on the best way to accomplish this. Scenerio:

Thread A is main thread. Thread B is a Com port listener that fires an
event when it receives input. I need to fire this event to Thread A yet
allow thread B to continue processing while thread A handles the event. I
have looked at using the Messaging classes but this looks like overkill to
accomplish this.

Any suggestions are greatly appreciated.

Thanks

Bob

Nov 16 '05 #4

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

Similar topics

2
1665
by: Kory Pukash | last post by:
I have an asp.net(2003) form that uses web server controls event architecture. The form has edit, cancel, save, delete buttons on it. When the delete button is clicked the following events fire. PageLoad btnDelete_Click PageLoad btnDelete_Click
5
10783
by: Richard | last post by:
All, I have a worker thread that fires events across threads to both GUI objects and thread agnostic objects. My code is working but I want to be assured that it did it "the right way"... Question: Is there a better way? According to the .NET docs that I read all that I have to do to fire my custom "OnSynchronizationStatusChange()"...
3
2284
by: Mike | last post by:
Hi, I am adding controls dynamically in a WebForm, but none of these controls' events fire. Here is the class code I am using. I have tried so many things, but nothing works :-( namespace WebApplication1 { using System;
28
10231
by: Tim_Mac | last post by:
hi, i'm new to .net 2.0, and am just starting to get to grips with the gridview. my page has autoEventWireUp set to true, which i gather is supposed to figure out which handlers to invoke when appropriate based on your method names . the GridView has OnRowCommand="GridView1_RowCommand" in the aspx. my problem is that the RowCommand event...
5
4640
by: Joe | last post by:
Hi I am adding a class to a ComboBox - and all is fine except that I fill the combobox on the Form_Load Method and it causes the method private void comboBox2_SelectedIndexChanged(object sender, EventArgs e) To fire twice Once when I comboBox2.DataSource = allMonths; And again when I execute comboBox2.DisplayMember = "Name";
11
1700
by: PokerMan | last post by:
Hi I have a situation where a method is fired from receiving a message from my server. On receiving this message it triggers a visual animation. So what happens when the server sends say 3 messages in quick succession. I want the method to fire, animate completely, and then fire again, finish
5
2792
by: =?Utf-8?B?VmFubmk=?= | last post by:
Hi, I have a component where I need to have thread-safe access to a list. Operations on the list are done in critical sections (lock (lockObject) { ... } ) in the usual way, to make sure that no other thread will modify the list while operations are running. However, I at the end of the critical section, I need to fire an OnChange type...
4
2035
by: Joergen Bech | last post by:
I sometimes use delegates for broadcasting "StateChanged" events, i.e. if I have multiple forms and/or controls that need updating at the same time as the result of a change in a global/common object, I keep local references to this object in each UI object, e.g. Private WithEvents _tools As RepeatTools and catch messages in an event...
4
1269
by: jake | last post by:
I am new to multi-threading. Here is my scenario: foreach (<file in a certain folder>) new Thread((ThreadStart)(delegate { processFile(<file>); })).Start(); sometimes misses firing some threads to process files. It misses firing different threads every time I run it. I suppose it all depends on the time-slice it is getting at that...
0
7526
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7457
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7965
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
1
7483
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For...
0
6051
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5375
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
3504
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3487
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
771
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.