Asynchronous Web Service and cancelability

  • Thread starter Thread starter Nathan
  • Start date Start date
N

Nathan

I have a loop that requests blocks of data through a web service, and
inserts each in turn into a SQL Server CE database.

It sounds like a good candidate for asynchronous web service calls.

So I would call Begin with a call back. When the callback is called, insert
result into the database.

However, the user could decide to quit and download no further data. This
doesn't sound safe as there are still threads running. If the form is
closed, the callback could no longer be valid. Worse yet, as we know about
the Pocket PC platform, those threads could keep running if the program is
closed. (No thread.abort available.)

Any suggestions?

Nathan
 
You need to call Abort() on the web service proxy class for every pending
request.
 
Alex Feinman said:
You need to call Abort() on the web service proxy class for every pending
request.

Thanks. I found what I needed there.

Nathan
--

Abort cancels a synchronous XML Web service request. Since a synchronous
request will block the thread until the response has been processed you must
call Abort from a separate thread. Calling Abort will cause a WebException
to be thrown from the XML Web service method call. The WebException.Status
property will have the value WebExceptionStatus.RequestCanceled. To abort an
asynchronous call, you need to cast the IAsyncResult returned from the Begin
method to a WebClientAsyncResult and call the WebClientAsyncResult.Abort
method.
 
Back
Top