We have a C# backend application here at work that I've written. It saves it's state to a txt file so that when it starts up again it'll have the details it needs to continue working. If I add a key to the registry to start the app when the user signs on (HKCU) then the app will start but it fails to read it's state txt file.
I don't know what's happening here. The txt file has to be in the same folder as the app and I load it like this:
String savepath = Path.Combine(Path.GetDirectoryName(Application.ExecutablePath), SaveFile);
if (File.Exists(savepath)) LoadState();
And I actually read the file using:
String[] lines = File.ReadAllLines(SaveFile);
None of this is really complicated but because the contents of the txt file aren't being loaded, I am assuming that either 1) the File.Exists()
is coming back false or 2) it's coming back true and File.ReadAllLines()
is coming back empty.
If I close the program and immediately re-run it then it reads the file just fine. What can I do to have my app read it's file when the computer starts up?