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
            Try
                clientSocket.Connect("127.0.0.1", 27015)
                Console.WriteLine("Running")
            Catch ex As Exception
                Console.WriteLine("Crashed")
                Dim pProcess() As Process = System.Diagnostics.Process.GetProcessesByName("ssrcds")
                For Each p As Process In pProcess
                    p.Kill()
                Next
                System.Diagnostics.Process.Start("C:\....")
            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.

Recommended Answers

All 2 Replies

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.