AutoResetEvent配合webClient.DownloadDataAsync 接收不到信号问题
public MainWindow()
{
InitializeComponent();
///////////////////////////////////////////////////////
AutoResetEvent downloadWaitEvent = new AutoResetEvent(false);
WebClient webClient = new WebClient();
webClient.DownloadDataCompleted += new DownloadDataCompletedEventHandler(rr);
var imgUrl = "http://img4.cache.netease.com/m/2013/12/18/20131218104403bd5df.png";//
//
webClient.DownloadDataAsync(new Uri(imgUrl), downloadWaitEvent);
if (downloadWaitEvent.WaitOne(10000)) //
{
//
System.Windows.MessageBox.Show("ll");
//
}
else
{
webClient.CancelAsync();
System.Windows.MessageBox.Show("CancelAsync");
}
}
private void rr(object sender, DownloadDataCompletedEventArgs e)
{
//
var waiterTmp = (AutoResetEvent)e.UserState;
//
try
{
//
if (!e.Cancelled && e.Error == null)
{
var bytes = e.Result;
//
}
}
finally
{
//
waiterTmp.Set(); //
//
}
}
相关推荐
C#同步、异步远程下载文件实例
通过调用DownloadDataAsync()方法开始异步下载,并传入一个AutoResetEvent对象作为信号,以便在下载完成后通知主线程。4.
网页页面图片批量下载
运行环境 .NET Framework2.0 开发工具 Microsoft Visual Studio 2005 二. 部分代码说明(主要讲解异步分析和下载):
JEP30-PX100A PartModel Product Guidelines for Electronic-Device Substrates and Assemblies – XML Requ
JEP30-PX100A PartModel Product Guidelines for Electronic-Device Substrates and Assemblies – XML Requirements
基于Matlab的自动睡眠粒状结构检测算法,从脑电信号中进行。.zip
1.版本:matlab2014a/2019b/2024b 2.附赠案例数据可直接运行。 3.代码特点:参数化编程、参数可方便更改、代码编程思路清晰、注释明细。 4.适用对象:计算机,电子信息工程、数学等专业的大学生课程设计、期末大作业和毕业设计。
JEP375 2.5D_3D Silicon thinned wafers with Through Silicon Vias (TSV’s) and Backside Redistribution
JEP375 2.5D_3D Silicon thinned wafers with Through Silicon Vias (TSV’s) and Backside Redistribution Layer (RDL).pdf


