您好,我的项目需要一些帮助。所以程序会崩溃,如果它执行一个需要互联网的代码我想知道如何命令我的应用程序检查是否有互联网然后继续,如果有互联网并提示用户连接到互联网如果没有连接到互联网
Public Sub CheckForUpdates()
If ProgressBar1.Value = 100 Then
Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://dl.dropbox.com/u/46370133/Noter/Version.txt.txt")
Dim response As System.Net.HttpWebResponse = request.GetResponse()
Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())
Dim newestversion As String = sr.ReadToEnd()
Dim currentversion As String = Application.ProductVersion
If newestversion.Contains(currentversion) Then
Button1.Text = ("You are up todate!")
label2.text = ("You may now close this dialog")
Else
Button1.Text = ("Downloading update!")
WebBrowser1.Navigate("http://dl.dropbox.com/u/46370133/Noter/Noter.exe")
label2.text = ("You may now close this dialog")
End If
End If
Button
Button1.Enabled = False
Button1.Text = "Checking for updates..."
Timer1.Start()
Label1.Text = ProgressBar1.Value
CheckForUpdates()
timer
ProgressBar1.Increment(5)
Label1.Text = ProgressBar1.Value
If ProgressBar1.Value = 100 Then
Timer1.Stop()
If ProgressBar1.Value = 100 Then
Dim request As System.Net.HttpWebRequest = System.Net.HttpWebRequest.Create("http://dl.dropbox.com/u/46370133/Noter/Version.txt.txt")
Dim response As System.Net.HttpWebResponse = request.GetResponse()
Dim sr As System.IO.StreamReader = New System.IO.StreamReader(response.GetResponseStream())
Dim newestversion As String = sr.ReadToEnd()
Dim currentversion As String = Application.ProductVersion
If newestversion.Contains(currentversion) Then
Button1.Text = ("You are up todate!")
label2.text = ("You may now close this dialog")
Else
Button1.Text = ("Downloading update!")
WebBrowser1.Navigate("http://dl.dropbox.com/u/46370133/Noter/Noter.exe")
label2.text = ("You may now close this dialog")
End If
End If
End If
答案 0 :(得分:0)
如果My.Computer.Network.Ping(" www.Google.com")那么
MsgBox("Internet Ok")
Else
MsgBox("No Internet")
End If