11using Microsoft . Extensions . Logging ;
2+ using System . Diagnostics ;
23using System . IO . Pipes ;
34
45namespace FileSyncAppWin
@@ -7,17 +8,19 @@ internal static class Program
78 {
89
910 private static Mutex mutex = new Mutex ( true , "PraewemaFileSyncAppWin" ) ;
10- private static volatile bool autoRestart = true ;
11+ internal static volatile bool autoRestart = true ;
1112 private static ILogger logger ;
1213 private static Form mainForm ;
1314 private const string PipeName = "PraewemaFileSyncAppWinPipe" ;
15+ private static string [ ] _args ;
1416
1517 /// <summary>
1618 /// The main entry point for the application.
1719 /// </summary>
1820 [ STAThread ]
1921 static void Main ( string [ ] args )
2022 {
23+ _args = args ;
2124 FileSyncApp . Program . ConfigureLogger ( args . FirstOrDefault ( ) ) ;
2225 logger = FileSyncApp . Program . LoggerFactory . CreateLogger ( "FileSyncAppWin" ) ;
2326 if ( args . Contains ( "noautorestart" ) )
@@ -147,13 +150,17 @@ private static void RestartApplication()
147150 if ( autoRestart )
148151 {
149152 // Get the path of the current application
150- string assemblyPath = System . Diagnostics . Process . GetCurrentProcess ( ) . MainModule . FileName ;
153+ string assemblyPath = Environment . ProcessPath ;
151154 // Restart the application using the path
152155 logger ? . LogInformation ( "RestartApplication, starting new process {A}" , assemblyPath ) ;
153- System . Diagnostics . Process . Start ( assemblyPath ) ;
156+ ProcessStartInfo processStartInfo = new ProcessStartInfo ( assemblyPath ) ;
157+ processStartInfo . Arguments = string . Join ( ' ' , _args ) ;
158+ processStartInfo . WorkingDirectory = Path . GetDirectoryName ( assemblyPath ) ;
159+ Process . Start ( assemblyPath ) ;
154160
155161 // Exit the current instance of the application
156- Environment . Exit ( 0 ) ;
162+
163+ Environment . Exit ( - 1 ) ;
157164 }
158165 else
159166 {
0 commit comments