0
Imports System.Net.NetworkInformation
Public Class Form1

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Timer1.Enabled = True
    End Sub

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick

        Dim pingtarget As String = "88.250.204.138"
        Dim pingre As PingReply = Ping.Send(pingtarget)

        If My.Computer.Network.Ping("pingtarget", 9002) Then

           address.ForeColor = Color.Green

           Do While My.Computer.Network.Ping("pingtarget", 9002)

                Me.ListBox1.Items.Add("Response from " & pingtarget & " in " & pingre.RoundtripTime.ToString() & " ms")
                My.Computer.Network.Ping("pingtarget", 9002)

            Loop


        Else
            Timer2.Enabled = True
            address.ForeColor = Color.Red
            MsgBox("Connection Failed")
        End If

    End Sub

End Class

Hey guys, I just began trying to develop a program that will keep pinging the server and if connection is lost, the client will reboot itself. I have some questions :

1- How to count the reboots? Otherwise it will keep rebooting as long as there is no connection. Reboots will retry connecting internet again but it fails too much, there must be a way to stop it. For example after 3 reboots , the client will run even without connection.

2- In these codes, when there is no connection, I get aa error message saying "An unhandled exception of type 'System.InvalidOperationException' occurred in Microsoft.VisualBasic.dll".

4

1 回答 1

0

一个明显的问题:

更改这部分代码:

My.Computer.Network.Ping("pingtarget", 9002)

对此:

My.Computer.Network.Ping(pingtarget, 9002)

pingtarget作为字符串而不是变量传递。

于 2013-09-26T03:13:45.963 回答