Cross thread call error

I am using VB.NET 2005

I have the following application structure:

UI form, a middle layer and a low level layer. They are all running in the same thread.

The low-level object creates a serial port (the .NET one):

New SerialPort(port, 57600, Parity.None, 8, StopBits.One)

and handle its events. Some of these event handlers throw events that are handled by the middle layer that in turn throw events that are handled by the UI.

The serial port is running on a different thread than the application and hence the event handlers are not running within the low level's thread.

The end result of the chain of events mentioned above is that I am getting an error in the UI level about cross thread calls.

I want to handle the serial port's event in the same thread of the low level object or at least when I throw events I want to throw them in the application's thread.

Is there a way to do it

Thank you



Answer this question

Cross thread call error

  • exulted

    It seems to me that the .NET 2005 SerialPort (System.IO.Ports.SerialPort) is created on a different thread (by default) as it throws events on a different thread than that of the application. I haven't used threading and the creation of the SerialPort was done in the following line:

    New SerialPort(port, 57600, Parity.None, 8, StopBits.One)


  • Randy Miller

    This is what I was getting at Richard... Is the different thread really needed



  • Amit Grover

    Judging from his constructor it's 57.6 datarate. Anyway, anytime you try to interact with controls created on the UI from a different thread, you are going to have to delegate the interaction.

    See this post for an example of how interact with a UI control from a different thread: http://forums.microsoft.com/MSDN/ShowPost.aspx PostID=181356&SiteID=1


  • Shekar Gudi

    Renee some events just fire on a different thread.


  • Carlos Valenzuela

     

    I know... technically they create a new thread.......

    But you know I've never seen an event be cross threadrd with a control. Perhaps it's just the way I code, I dont know.



  • Menko

    Joe,

    I have a couple of questions.... What are you attempting to gain by multithreading What is your datarate



  • Cross thread call error