VB.net Auto Restart Application

I have a code here that will start a process and when pressed again it will kill the current process and start a new one(restart).

 Private Games As New Dictionary(Of String, Process)

Private Sub GS1_Click(sender As Object, e As EventArgs) Handles GS1.Click
    Dim gameservercfg As String = GameServer1.Text
    Dim Key As String = gameservercfg.ToUpper

    If Games.ContainsKey(Key) Then
        If Not Games(Key).HasExited Then
            Games(Key).Kill()
        End If
        Games.Remove(Key)
    End If

    Dim psi As New ProcessStartInfo
    psi.FileName = System.IO.Path.Combine(Directory.GetCurrentDirectory(), "GameServer.exe")
    psi.WorkingDirectory = System.IO.Path.GetDirectoryName(psi.FileName)
    psi.Arguments = gameservercfg
    Games.Add(Key, System.Diagnostics.Process.Start(psi))
End Sub

What I want to do is, how to make it auto restart when that gameserver.exe crashes by itself?

Answers


The basic idea that could work in such a scenario is that you save any configuration to a file onto the disk. Then restart the application using

System.Windows.Forms.Application.Restart()

And on application start event load any data from the disk file where you saved your configuration, if any. For more insight into the topic you may also read these SO posts auto-restart-and-then-continue-the-sub-in-vb-net application-restart-puzzling-behaviour-in-vb-net

Additionally you may (1) save your configuration, (2) start a new independent instance of the same application and (3) then end the current instance. Do not forget to load saved/default configurations from the saved file on application start/restart, if required.


Need Your Help

TextView.setVisibility isn't working.

android textview android-linearlayout

I'm trying to set a TextView to invisible via code, but it just won't work. My XML declaration is (inside a LinearLayout):

Weblogic and Hibernate 3.6.5, migrating DB layer from Oracle 10g to 11g, pitfalls, gotachas and experiences?

java hibernate oracle10g weblogic oracle11gr2

We currently have a large enterprise java-based codebase consisting of numerous legacy and new projects running within Weblogic using frameworks such as struts 1, spring MVC, etc.