【问题标题】:VB.net Auto Restart ApplicationVB.net 自动重启应用
【发布时间】:2015-10-04 15:29:54
【问题描述】:

我这里有一个代码,它将启动一个进程,当再次按下它时,它将终止当前进程并启动一个新进程(重新启动)。

 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

我想做的是,当gameserver.exe自行崩溃时,如何让它自动重启?

【问题讨论】:

    标签: vb.net process.start application-restart


    【解决方案1】:

    可以在这种情况下工作的基本想法是将任何配置保存到磁盘上的文件中。然后使用

    重新启动应用程序
    System.Windows.Forms.Application.Restart()
    

    并在应用程序启动事件中从您保存配置的磁盘文件中加载任何数据(如果有)。要更深入地了解该主题,您还可以阅读这些 SO 帖子
    auto-restart-and-then-continue-the-sub-in-vb-net
    application-restart-puzzling-behaviour-in-vb-net

    此外,您还可以 (1) 保存配置,(2) 启动同一应用程序的新独立实例,(3) 然后结束当前实例。
    如果需要,不要忘记在应用程序启动/重新启动时从保存的文件中加载保存的/默认配置。

    【讨论】:

      猜你喜欢
      • 2014-05-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-01-21
      • 2011-03-04
      • 2018-10-22
      相关资源
      最近更新 更多