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() {
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.
source share