ターゲットフレームワークを3.5から4.0に変更しました。それ以外の変更はありません。 3.5で動作していた単純なpingでは、結果が4.0になり、Canceled = Trueとなります。これを引き起こす原因は何ですか?NetworkInformation.Ping()、.NET 4.0でキャンセルされた結果(3.5ではなく)
Public Sub StartInternetConnectionCheckEvery(ByVal seconds As Integer)
Dim timer As New Timer()
timer.Interval = seconds * 1000
AddHandler timer.Tick, AddressOf CheckIsConnectedToInternet
timer.Start()
End Sub
Private Sub CheckIsConnectedToInternetByTimer(ByVal sender As Object, ByVal e As System.EventArgs)
CheckIsConnectedToInternet()
End Sub
Public Sub CheckIsConnectedToInternet()
Using ping As New System.Net.NetworkInformation.Ping()
Dim address As String = "www.google.com"
ping.SendAsync(address, Nothing)
AddHandler ping.PingCompleted, AddressOf OnPingResult
End Using
End Sub
Private Sub OnPingResult(ByVal sender As Object, ByVal e As PingCompletedEventArgs)
If e.Cancelled Then
Trace.WriteLine("InternetHelper: Ping Cancelled")
Return
End If
IsConnectedToInternet = (e.Reply.Status = IPStatus.Success)
RaiseEvent InternetPingResult(IsConnectedToInternet)
End Sub
を破ることができる、しかし確実に、より多くの大規模なサイトがpingに応答しないどのように素敵なデモンストレーション。それはあなたのコードのエラーではなく、考えることです。 – dbasnett