"Max" <ma******@yahoo.comwrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
Hello,
I made an application that uses the main thread for the UI, and another
thread to communicate through the RS232 port. I would like the
communication thread to be suspended immediately when the user presses the
ESC key. It should resume when the user answers a dialog box. The
Thread.Suspend cannot be used anymore in .NET and I'm trying to figure out
how to do this differently. Can anyone help?
In reality, there's no need for a separate thread to accomplish what you
describe. Windows serial ports fully support overlapped I/O completion
callbacks. However the serial port class in the .NET Framework BCL doesn't
expose this functionality, and the .NET message loop doesn't wait alertably,
so you can't even implement this single threaded design via P/Invoke.
However, using overlapped I/O with completion callbacks is entirely possible
in your second thread, then you use an alertable wait
(WaitForSingleObjectEx) to wait for I/O events to occur, or if you set your
suspend/exit event. If you need more wakeup conditions, there's also
WaitForMultipleObjectsEx.
Another way, requiring Vista, is to P/Invoke CancelIoEx to interrupt your
current I/O operation.
>
Cheers,
Max.