DownloadFileAsync:需要检查是否没有互联网连接或下载失败 [英] DownloadFileAsync : Need check if no internet conenction or if download failed

查看:200
本文介绍了DownloadFileAsync:需要检查是否没有互联网连接或下载失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一段代码使用DownloadFileAsync下载文件.如果我断开互联网连接,则该按钮会单击,并且什么也没有发生.如果互联网断开以及下载失败,我想抛出一个异常.关于如何实现这一目标的任何想法 ?谢谢

I have a chunk of code that downloads a file using DownloadFileAsync. If I disconnect the internet the button clicks and nothing happens. I want to throw an exception if the internet is down and also if the download fails. Any ideas on how to achieve this ? Thanks

 Private Sub downloadFile(ByVal srcPath As String, ByVal destPath As String)
        Dim wClient As New System.Net.WebClient()
        AddHandler wClient.DownloadProgressChanged, AddressOf downloadFile_ProgressChanged
        wClient.DownloadFileAsync(New System.Uri(srcPath), destPath)
    End Sub

推荐答案

您可以使用Ping类检查Internet连接是否可用
You can use the Ping class to check if Internet connection is available http://msdn.microsoft.com/en-us/library/system.net.networkinformation.ping.send.aspx.


这篇关于DownloadFileAsync:需要检查是否没有互联网连接或下载失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆