fix reoccurring entry dll path in args when application restarts
This commit is contained in:
39
Torch.Server/ApplicationRestartHelper.cs
Normal file
39
Torch.Server/ApplicationRestartHelper.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
|
||||
namespace Torch.Server;
|
||||
|
||||
internal static class ApplicationRestartHelper
|
||||
{
|
||||
public static void RestartApplication()
|
||||
{
|
||||
var exe = Path.Combine(AppContext.BaseDirectory, "Torch.Server.exe");
|
||||
|
||||
var args = Environment.GetCommandLineArgs().ToList();
|
||||
|
||||
args.RemoveAt(0); // dll entry path
|
||||
|
||||
args.RemoveConfigItem("--tempAutostart");
|
||||
args.RemoveConfigItem("--waitForPid");
|
||||
|
||||
args.AddRange([
|
||||
"--waitForPid", Environment.ProcessId.ToString(),
|
||||
"--tempAutostart", "true"
|
||||
]);
|
||||
|
||||
Process.Start(new ProcessStartInfo(exe, args));
|
||||
}
|
||||
|
||||
private static void RemoveConfigItem(this List<string> list, string item)
|
||||
{
|
||||
var index = list.BinarySearch(item, StringComparer.OrdinalIgnoreCase);
|
||||
|
||||
if (index < 0) return;
|
||||
|
||||
list.RemoveAt(index);
|
||||
list.RemoveAt(index);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user