communicating between threads

A

aaronj1335

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.
 
A

aaronj1335

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top