WebClient.CancelAsync() is funky.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 1 of 1

Thread: WebClient.CancelAsync() is funky.

  1. #1
    Join Date
    Jul 2007

    WebClient.CancelAsync() is funky.

    .NET 3.5 (WebClient from .NET 1.1)

    I'm using a WebClient class to check a file on an FTP server at specified intervals using a timer. I basically call WebClient.DownloadStringAsync() and wait for the WebClient.DownloadStringAsyncCompleted event to be fired and then do some processing with the result. However, the call to DownloadStringAsync() blocks the calling thread for a period of time and if you call WebClient.CancelAsync() during that time from another thread, it causes some problems. It will not actually cancel the async operation and the WebClient will never change from a busy state (IsBusy property will remain true indefinitely) and the DownloadStringAsyncCompleted event will never get raised.

    This is a rather noxious problem that I'm not sure how to get around. I could try implementing a WebRequest class, but the ease of using the WebClient class is tempting and I want to see if I can find a fix for it first. So far though, I don't think there is one without calling WebClient.Dispose() after the WebClient.CancelAsync() call which may result in some undefined behavior.
    Last edited by RaleTheBlade; February 14th, 2011 at 12:08 PM.
    R.I.P. 3.5" Floppy Drives
    "I know not with what weapons World War III will be fought, but World War IV will be fought with sticks and stones." - Albert Einstein

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

This is a Codeguru.com survey!

HTML5 Development Center