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

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 10066
Bob Lazarchik <bo*****@sditampa.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.com>
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*****@sditampa.com> wrote in message
news:ev**************@TK2MSFTNGP11.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(theParams)

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.BeginInvoke(theParams);
"Bob Lazarchik" <bo*****@sditampa.com> wrote in message
news:ev**************@TK2MSFTNGP11.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
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. ...
5
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"... ...
3
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...
28
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...
5
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...
11
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...
5
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...
4
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...
4
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...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....

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.