I have written a very basic serial terminal with a very basic form. There is a class which implements all the opening, closing, receiving and sending messages from the COM port and also contain a server method which initiate a new TCP channel so that an external client application will be able to connect to the object and run the method which sends a command from the client through TCP to the server. Of course the class inherits "MarshalByRefObject" class. Please see attached the solution containing the server and client.
My problem is as follows:
Once server is running and port is opened (by using the appropriate button in the form), I would like to send a command from the client. In order to do that there is a need to create an instance of that class (the one which inherits from MarshalByRefObject) so that I'll have the method of writing to the port, however, I encounter the "Cross-thread operation not valid: Control 'textBox1' accessed from a thread other than the thread it was created on." error message. I cannot do the BeginInvoke trick there... I'm having troubles to make it work though I'm quite close.
1) Should I use a static class for that?
2) Assuming I want to access variables in the server, as I'm creating a new instance of the class in the client, will I be able to access them?
Number of downloads: 32