Restart an application by itself

后端 未结 10 636
醉话见心
醉话见心 2020-12-13 02:46

I want to build my application with the function to restart itself. I found on codeproject

ProcessStartInfo Info=new ProcessStartInfo();
Info.Arguments=\"/C          


        
10条回答
  •  臣服心动
    2020-12-13 03:28

    Why not just the following?

    Process.Start(Application.ExecutablePath); 
    Application.Exit();
    

    If you want to be sure the app does not run twice either use Environment.Exit(-1) which kills the process instantaneously (not really the nice way) or something like starting a second app, which checks for the process of the main app and starts it again as soon as the process is gone.

提交回复
热议问题