Hello i have been trying to make a program that should restart my server if it crashes. Just some few problems... it won't work.

Imports System.Net.Sockets
Imports System.Text
Module Module1
    Sub Main()
        Console.Title = "Shifty Server Keeper"
        Dim clientSocket As New System.Net.Sockets.TcpClient()
        While clientSocket.Connected = False
                clientSocket.Connect("", 27015)
            Catch ex As Exception
                Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("ssrcds")
                For Each p As Process In pProcess
            End Try
        End While
        While clientSocket.Connected = True
        End While
    End Sub
End Module

My problem is that when it notices the program runs, it won't do the process again, and just stop watching for the server crash. Please tell me a way to make it repeat :)
I tryet do a Do...Loop but i don't seem to do it right.

Edited by Qvintus: n/a

7 Years
Discussion Span
Last Post by Qvintus

Running code in a constant/endless loop would be exactly that, your program freezing up the pc because its constantly running something over & over to search your server's status.

If keeping in a console app, I would set it up so that the windows task scheduler runs the process once at interval set times or create it as a windows process. Another option is to create a windows app on a timer basis but again, this would be a program constantly running in the background.


So you have any eksample code i could look at to make it better or?
yea... I know the app. Timer would just freeze the program it self. while if i run it in cmd app. it works okay. The problem is just how should i put it up to get it to work?
Should i make a public function to look for connection to server. That returns true every time the program can't connect to the server, or? yea any kind of eksample that could help me to a final working program.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.