1

我使用 WebClient.DownloadDataAsync() 从网络下载数据。

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

我怎么解决这个问题?

4

1 回答 1

0

这是一个已知的错误,应该在 2.10 中修复。

于 2012-05-21T18:09:59.800 回答