Start executing the exe file in the windows, restart the computer and pick up where the process ended

Is it possible? If so, how? The stream will be something like this:

private void DoStuff() { // Do some stuff RestartPc(); } private void RestartPc() { Process.Start("shutdown", "/r /t 0"); } // Call this when the PC is restarted: private void DoStuffAfterRestart() {} 

All this code will be a Windows service , so it would be a "better" way to tell the OnStart method to skip DoStuff if the pc was rebooted and go straight to DoStuffAfterRestart , since the service will have an automatic start.

+5
source share
1 answer

Idk, if there are special methods for this, but I will have a solution:

Add your program to autorun. EDIT: As @PTwr pointed out, you shouldn't use regular autorun. Instead, use the Run once registry key .

Change the code to something like this:

 public static void main(string[] args) { var x = loadState(); if(x == null) DoStuff(); else DoStuffAfterRestart(); } private void DoStuff() { // Do some stuff SafeState(); RestartPc(); } // Call this when the PC is restarted: private void DoStuffAfterRestart() {} 

In safe / load methods, you will need to write something to a file / registry in order to remember the current state

Keeping your current position, you can “remember” where you were last, and do the right thing after a reboot.

+2
source

All Articles