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

communicating between threads

I am trying to write an application that controls a robot via a
serial
port. I made a robot class that includes the serial port over which
I
send commands, and I would like to be able to have two different
threads for the GUI and for the loop that sends commands to the
robot,
but I am having trouble communicating between the threads. Right
now
I am trying to get the GUI thread to raise an event when the user
sends a command that the robot thread needs to handles, and the robot
thread to raise an event when the robot sends anything over the
serial
port or finishes a command that the GUI thread needs to respond to. I
would like to know if this is the best implementation and what I will
need to do as far as delegates between the two threads. I would use
a
BackgroundWorker, but I need to be able to send commands to the
BackgroundWorker while it is working, which does not seem to be what
it is designed for. Any help would be greatly appreciated, thanks.
Jun 27 '08 #1
2 1304
On Jun 2, 8:09*am, aaronj1335 <aaron.r.st...@gmail.comwrote:
I am trying to write an application that controls a robot via a
serial
port. *I made a robot class that includes the serial port over which
I
send commands, and I would like to be able to have two different
threads for the GUI and for the loop that sends commands to the
robot,
but I am having trouble communicating between the threads. *Right
now
I am trying to get the GUI thread to raise an event when the user
sends a command that the robot thread needs to handles, and the robot
thread to raise an event when the robot sends anything over the
serial
port or finishes a command that the GUI thread needs to respond to. I
would like to know if this is the best implementation and what I will
need to do as far as delegates between the two threads. *I would use
a
BackgroundWorker, but I need to be able to send commands to the
BackgroundWorker while it is working, which does not seem to be what
it is designed for. *Any help would be greatly appreciated, thanks.
Right now I have my Form1 class, and my RobotController class. The
RobotController class raises a MessageEvent. I have a
RobotControllerThread that is a New System.Threading.Thread(AddressOf
RobotController.Go), and the RobotController class has a
MessageEvent. So basically my Form1 loads up, starts a new thread at
the address of a subroutine in the RobotController, and then the
RobotController's subroutine raises the MessageEvent when it wants to
tell something to Form1. The problem is that I cannot handle the
MessageEvent in the Form1 class because it doesn't have the same
signature as the RobotController class that raised the event. How can
I raise an event in the thread that's running the RobotController
class subroutine, and handle it in the Form1 class?
Jun 27 '08 #2
How can
I raise an event in the thread that's running the RobotController
class subroutine, and handle it in the Form1 class?
See InvokeRequired, Invoke pair in Google....
The problem is that I cannot handle the
MessageEvent in the Form1 class because it doesn't have the same
signature as the RobotController class that raised the event
is unclear to me... The routine that handles this event is AFAIK defined by
you so it could have whatever signature you defined ?? (and what in the
RobotController, the *class* doesn't have a signature do you mean the
"event" ?)

Depending on what you are after you could also look at a consumer/producer
scheme (Google should return numerous hits about this). Finally
http://msdn.microsoft.com/en-us/robotics/default.aspx and around could
perhaps helps. In partiuclar I believe I saw there is a SDK on this subject
that should likely provide seom interesting code samples...

--
Patrice

Jun 27 '08 #3

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

Similar topics

1
by: Martin | last post by:
This is probably a very easy one but I just can't put my finger on the communicating events name:- I have a MDIform with a couple of child forms. The child forms scroll vertically at run time...
2
by: Eric Brunel | last post by:
Hi all, We're trying to communicate with Microsoft Visual C++ 6.0 via COM to make it perform a few operations. Our main need is to set a breakpoint on a given line in a given file. We ended up...
3
by: Michael Sparks | last post by:
Hi, I'm posting a link to this since I hope it's of interest to people here :) I've written up the talk I gave at ACCU Python UK on the Kamaelia Framework, and it's been published as a BBC...
0
by: David Dolheguy | last post by:
I have written an application using VB.Net 2003 which contains a single timer control (Interval set to 5 seconds) and a function which uses the BeginReceiveFrom Socket function. The problem I am...
1
by: valere | last post by:
I look for information for communicating between JavaScript and a native plugin. I noticed that LiveConnect is oriented to communicate as a "bridge" between Java and JS. But how to process with a...
3
by: Stan | last post by:
Hallo, I have developed an application in MS Access 2000 (Polish version) under MS Windows XP prof (also Polish). Now I would like to run this code on MS Windows XP EN and MS Access XP EN. I have...
6
by: Joe Jax | last post by:
I have an object that spawns a worker thread to process one of its methods. That method processes methods on a collection of other objects. During this processing, a user may request to cancel the...
5
by: jehugaleahsa | last post by:
Hello: I want to have a class that sends messages to a textbox. However, I want the message sender to be in a different thread than the message displayer, so users can scroll through the...
6
by: dolulob | last post by:
Hi, I'm trying to communicate with a console application through a c# program. the console application is micq a console based ICQ client. I want to be able to send an receive messages through...
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
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.