Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/multithreading/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Multithreading Monotouch Webclient.CancelAsync ThreadInterruptedException_Multithreading_Xamarin.ios_Webclient_Interrupted Exception_Webclient Download - Fatal编程技术网

Multithreading Monotouch Webclient.CancelAsync ThreadInterruptedException

Multithreading Monotouch Webclient.CancelAsync ThreadInterruptedException,multithreading,xamarin.ios,webclient,interrupted-exception,webclient-download,Multithreading,Xamarin.ios,Webclient,Interrupted Exception,Webclient Download,我使用WebClient.DownloadDataAsync()从web下载数据 WebClient webClient; void WebClientDownload(MediaInfo media) { if (webClient == null) { webClient = new WebClient(); webClient.DownloadProgressChanged += (sender, e) => {

我使用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
如何解决此问题?

这是一个应在2.10中修复的问题