English 中文(简体)
Monotouch 网页客户端。 CancelAsync 串列中断例外
原标题:Monotouch Webclient.CancelAsync ThreadInterruptedException

我用 WebClient. downloadDataAsync () 从 Web 下载数据 。

WebClient webClient;
void WebClientDownload(MediaInfo media)
{
    if (webClient == null)
    {
        webClient = new WebClient();
        webClient.DownloadProgressChanged += (sender, e) => {
            // use e.ProgressPercentage for change UIProgressView.Progress value by InvokeOnMainThread
        };
        webClient.DownloadDataCompleted += (sender, e) => {
            if (e.Cancelled == false && e.Error == null)
            {
                // saveing data
            }
        };
    }

    webClient.DownloadDataAsync(new Uri("http://..."));
}

但当我使用 webClient.CancelAsync (); 来取消下载时, 我得到了这个例外 :

System.Threading.ThreadInterruptedException: Thread interrupted
  at (wrapper managed-to-native) System.Threading.WaitHandle:WaitOne_internal (System.Threading.WaitHandle,intptr,int,bool)
  at System.Threading.WaitHandle.WaitOne (Int32 millisecondsTimeout, Boolean exitContext) [0x00038] in /Developer/MonoTouch/Source/mono/mcs/class/corlib/System.Threading/WaitHandle.cs:376
  at System.Net.WebAsyncResult.WaitUntilComplete (Int32 timeout, Boolean exitContext) [0x0000d] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/WebAsyncResult.cs:164
  at System.Net.WebConnectionStream.Read (System.Byte[] buffer, Int32 offset, Int32 size) [0x00018] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/WebConnectionStream.cs:327
  at System.Net.WebClient.ReadAll (System.Net.WebRequest request, System.Object userToken) [0x0010d] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/WebClient.cs:909
  at System.Net.WebClient.DownloadDataCore (System.Uri address, System.Object userToken) [0x0000a] in /Developer/MonoTouch/Source/mono/mcs/class/System/System.Net/WebClient.cs:246

我怎样才能解决这个问题?

问题回答




相关问题
Silverlight, Updating the UI during processing

I have a simple silverlight multifile upload application, and i want to provide the user with some feedback, right now its only in a test phase and i dont have the webservice. Somehow i cant get the ...

Is reading from an XmlDocument object thread safe?

I was wondering if i could safely read from an XmlDocument object using SelectNodes() and SelectSingleNode() from multiple threads with no problems. MSDN says that they are not guaranteed to be ...

Terminating a thread gracefully not using TerminateThread()

My application creates a thread and that runs in the background all the time. I can only terminate the thread manually, not from within the thread callback function. At the moment I am using ...

热门标签