views:

748

answers:

1

Hello,

I am developing in C# using the SerialPort class. SerialPort.Write() is a blocking method. How can I exit this method when I want to stop writing? I use a thread to write. I abort this thread when I want to stop writing but the COM port continues to write.

Any ideas?

Thanks a lot.

Sorry for my basic English.

A: 

SerialPort.Write() to break from it's blocked condition use calling SerialPort.DiscardOutBuffer(). This causes an IOException but that is ok as long as u can get out of the blocked condition cleanly.

bg