Monotouch Webclient.CancelAsync ThreadInterruptedException

Posted

技术标签:

【中文标题】Monotouch Webclient.CancelAsync ThreadInterruptedException【英文标题】: 【发布时间】:2012-05-28 05:24:54 【问题描述】:

我使用 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

我该如何解决这个问题?

【问题讨论】:

【参考方案1】:

这是一个known bug,应该在 2.10 中修复。

【讨论】:

以上是关于Monotouch Webclient.CancelAsync ThreadInterruptedException的主要内容,如果未能解决你的问题,请参考以下文章

Monotouch:了解委托机制模式

如何在 DialogViewController (Monotouch.Dialog) 上设置背景颜色

Monotouch 找不到 AudioFileOpenURL

MonoTouch:StoryBoarding - 手动转场?

MonoTouch 中的 ViewForZoomingInScrollView

MonoTouch 4.0 使用模拟器抛出 ReflectionTypeLoadException