Exe works in Windows C # service

I am writing using windows C # service. Tickers this way when it works without problems.

bool processIsRunning(string process) { return (System.Diagnostics.Process.GetProcessesByName(process).Length != 0); } if (!processIsRunning("notepad")) { Process.Start("notepad.exe"); } 

If the codes do not work this way.

 StreamReader read = new StreamReader(Environment.GetEnvironmentVariable("appdata") + "\\path.txt"); string path = oku.ReadLine(); string processname = Path.GetFileName("notepad"); if (processIsRunning(processname) == false) { System.Diagnostics.Process.Start(path); } 

I get the name of the program and the path to the program from the registry.

+4
source share
1 answer

Your question doesn't make much sense, but there are some possible problems if the code you posted is your complete code.

Your StreamReader is called read , but are you trying to read from a stream named oku ?

In addition, you did not show that you are actually closing the StreamReader, you would be better of using a block StreamReader, you would be better of using a using` to make sure that your stream is correctly closed and deleted.

 using (StreamReader read = new StreamReader(Environment.GetEnvironmentVariable("appdata") + "\\path.txt")) { string path = read.ReadLine(); string processname = Path.GetFileName("notepad"); if (processIsRunning(processname) == false) { System.Diagnostics.Process.Start(path); } } 
0
source

All Articles