I hope somebody can help me out here, been struggling with this for a few days and not getting anywhere.

The following code is from a class to control a serial port. The DataReceived event of the serial port is raised on a different thread to the one that created the serial port object and writes to it. I want to marshall any data received back onto the original thread. As the class does not inherit from Control, I do not have Invoke methods or .InvokeRequired property. I have tried all manner of delegate configurations, and also tried to implement ISynchronizeinvoke, without any succes, as basically I am not sure what I am doing.

Any help MASSIVELY appreciated.

c# Code:
  1. public void SendCommand(string cmd)
  2. {
  3.     //This runs on the thread the class was created on.
  4.     this._port.Write(cmd);
  5. }
  6.  
  7. private void _port_DataReceived(object sender, SerialDataReceivedEventArgs e)
  8. {
  9.     //The DataReceived event of the serial port is raised on a different thread.
  10.                    
  11.     byte[] data = new byte[this._port.BytesToRead];
  12.     int num = this._port.Read(data, 0, this._port.BytesToRead);
  13.  
  14.     //I want to pass 'data' to the GetBytes method, and run it on the same thread as SendCommand
  15. }
  16.  
  17. private void GetBytes(byte[] data)
  18. {
  19.     //Run this on the same thread as SendCommand.
  20. }


PS Not sure why there is corruption in the code snippet, but it should read byte[]