Hi Daniel,
I have just solved my problems :)
If I use the SerialPort.DiscardOutBuffer() operation, then the Read Callback
is called and then I can call SerialPort.EndRead(asyncResult);
So, the solution for me was to use "DiscardOutBuffer()".
Btw, It's not possible for me to use the PurgeComm() because I don't know
the Handle to the SerialPort that I'm using,
I haven't found any way to get the handle for the SerialPort. If someone
knows howto get the handle that the SerialPort is using, please let me know.
Allways good to know for the future :)
Thanks for your time & help!
Best Regards
Anders R
"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> skrev i
meddelandet news:Ob**************@TK2MSFTNGP02.phx.gbl...
"Anders R" <ab*@cnn.com> wrote in message
news:Os**************@TK2MSFTNGP04.phx.gbl... Hi Daniel,
Yes, I use the SerialPort.BaseStream.BeginRead() operation.
No, I can't use the ReadExisting operation and DataRecived event...
If there isn't any easy method, is there any other way to doit?
Digging around in the internals and see if the library they use offers a
way to cancel outstanding requests, and then pinvoking . I don't know what
the serial port class is built upon, alas. There is nothing I'm aware of
at the top level of the framework that allows canceling async operations.
However, have you tried using PurgeComm? Or perhaps just using pinvoke
instead of the serial port class? You might also be able to write your own
semi-async read code using a seperate thread and polling the BytesToRead
field.