如何在Webclient DownloadFileCompleted事件中检查文件是否已成功下载?

时间:2014-10-04 10:55:59

标签: c# .net winforms webclient

private void Client_DownloadFileCompleted(object sender, AsyncCompletedEventArgs e)
{
}

我想检查这两种情况:

  1. 如果出现错误,请执行某些操作。

  2. 如果文件已成功下载,请执行某些操作。

1 个答案:

答案 0 :(得分:2)

您可以检查AsyncCompletedEventArgs实例的ErrorCancelled属性:

if (e.Error != null)
{
    // there was an error, do something
}
else if (!e.Cancelled)
{
    // file was downloaded fine and completed, do something
}