473,320 Members | 1,719 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Cancel a pending async operation?

Hi,

Anyone know howto cancel a pending async operation?

I'm using the .NET 2.0 SerialPort and I start a BeginRead(...);
What I like to do is to cancel that pending read. In c++ or with api calls
you could use PurgeComm(handle, PURGE_RXABORT);

I can't use PurgeComm in my case, any suggestions?

Best Regards

Anders
Apr 7 '06 #1
4 7105

"Anders R" <ab*@cnn.com> wrote in message
news:u7**************@TK2MSFTNGP05.phx.gbl...
Hi,

Anyone know howto cancel a pending async operation?

I'm using the .NET 2.0 SerialPort and I start a BeginRead(...);
What I like to do is to cancel that pending read. In c++ or with api calls
you could use PurgeComm(handle, PURGE_RXABORT);
You start a begin read on what? The BaseStream?

Chances are there isn't an easy method, can you not use ReadExisting and the
DataRecieved event to get around needing async?
I can't use PurgeComm in my case, any suggestions?

Best Regards

Anders

Apr 10 '06 #2
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?

Regard
Anders

"Daniel O'Connell [C# MVP]" <onyxkirx@--NOSPAM--comcast.net> skrev i
meddelandet news:Ot*************@TK2MSFTNGP05.phx.gbl...

"Anders R" <ab*@cnn.com> wrote in message
news:u7**************@TK2MSFTNGP05.phx.gbl...
Hi,

Anyone know howto cancel a pending async operation?

I'm using the .NET 2.0 SerialPort and I start a BeginRead(...);
What I like to do is to cancel that pending read. In c++ or with api
calls
you could use PurgeComm(handle, PURGE_RXABORT);


You start a begin read on what? The BaseStream?

Chances are there isn't an easy method, can you not use ReadExisting and
the DataRecieved event to get around needing async?

I can't use PurgeComm in my case, any suggestions?

Best Regards

Anders


Apr 10 '06 #3

"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.
Apr 11 '06 #4
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.

Apr 11 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Steven | last post by:
Hello I need some help with canceling a thread. Here is a simple code that creates and cancels a thread. It does create a thread BUT it doesnt cancel it, am I doing this wrong? Thank you! ...
3
by: Jacob | last post by:
I'm writing a class that communicates with a server using the TcpClient class. Most of the methods I've written are intended to be used synchronously and will block until they are completed. But...
1
by: g18c | last post by:
Hi, is there anyway of canceling the BeginConnect operation on a socket? I would like my user to be able to hit a button to abort the connection attempt - i notice the sockets class does not...
7
by: satish mullapudi | last post by:
Hi All, I am using Db2 UDB v 8.2 on RHEL . I have performed a load operation on a table. Now that tablespace has been switched into RESTORE PENDING state. Now I can only read the data in the...
2
by: Robinson | last post by:
I can start an Asynchronous operation against a data source with SQLCommand.BeginExecuteReader, allowing me to loop, checking for user cancellation before the operation has completed, but how then...
10
by: Frankie | last post by:
It appears that System.Random would provide an acceptable means through which to generate a unique value used to identify multiple/concurrent asynchronous tasks. The usage of the value under...
1
by: Ryan Liu | last post by:
Hi, I have a 100 clients/ one server application, use ugly one thread pre client approach. And both side user sync I/O. I frequently see the error on server side(client side code is same, but...
16
by: parez | last post by:
I start a BackGroundWorker to populate a grid. It is started off in the ui layer The thread follows( cannot think of a better word) the path UI->Layer1->Layer2->Communication Layer and it...
0
by: karantech | last post by:
sir, can anybody plz give an easy explanation to me on how to cancel an asynchronous operation. i m using begininvoke, endinvoke async methods.
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.