Link to home
Start Free TrialLog in
Avatar of bbimis
bbimis

asked on

How do you restart a timer in vb.net

how do you restart a timer in vb.net?
i have tried timer1.stop then timer1.start  i have tried timer1.enabled = false then timer1.enabled = true  nothing seems to work
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Calling Stop and Start should do the trick? Why do you say it is not working? Any code to share?
Avatar of bbimis
bbimis

ASKER

here is what i have i have a timer1 and it starts on the form load and then the tick event is as follows
Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        thread1 = New Thread(New ThreadStart(AddressOf checker))
        thread1.Start()

    End Sub

    Public Sub checker()
        Dim stop1 As Integer = 0
        Try

            If My.Computer.Network.Ping(server.ToString()) Then
                tssStatus.Text = "Currently Online"
                'Me.Refresh()
                If stop1 = 1 Then
                    Timer1.Stop()
                End If
            End If

        Catch ex As Exception
            tssStatus.Text = "Offline"
            ' Me.Refresh()
            stop1 = 1
        End Try
    End Sub

    Private Sub ServerToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles ServerToolStripMenuItem.Click
        My.Settings.Server = InputBox("Enter Server name", "Server Name")

        Try
            thread1.Abort()
        Catch ex As Exception
        End Try
        Timer1.Enabled = False
        Timer1.Enabled = True
        Timer1.Start()



        tsbWhichServer.Text = "Using: " & My.Settings.Server.ToString()
    End Sub

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Éric Moreau
Éric Moreau
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of bbimis

ASKER

thanks i got it working. i had to put the server name in the inputbox section of the code. basically it wasn't updating the servername.
thanks for your help!