The problem with your code on this line
var message = ReceiveSerialPort.ReadLine();
You lock your code to wait for the line, if the line never appears, it will stay here forever or the value set to ReadTimeout
So why the line never arrives?
The problem may be an error in WriteLine("Test"); , you must handle errors, or it may be that your input blocks your ReadLine() code before WriteLine("Test") can pass, you can insert Thread.Sleep(100) between, but this does not improve the code.
Note Your code will also work, as sometimes, depending on the conditions of the race.
This synchronized / blocking reading from serial ports seems simple in code with only one line; but it creates many negative side effects in your communication protocol.
A much better solution (given that you like reading / writing data from the microcontroller) is to either use the stream as suggested by Yvette , or use Stream.BeginRead (Byte [], Int32, Int32, AsyncCallback, Object) asynchronously , which I would prefer.
Asynchronous reading will trigger an event when something arrives at the serial port. The main idea of ββthis programming strategy is not to do step-by-step programming, but to expect what will ever work out and then process it correctly.
In a communication protocol with asynchronous reading, AutoResetEvent is very useful, so you send something, then run AutoResetEvent , if the expected result is asynchronously expected, you set this event, and your code can continue if AutoResetEvent and you can handle it with this.