Question abt Service
-
Hi, I am trying find the services which are running on my machine on polling basis, and I am trying write this to a file before shutdown. I am trying to do this using a service, I am writing the code for file writing in the OnStop() method of the service. The problem is my service starts and stops immediately. Why this is happening?? Code Snippet: OnStop() { System.IO.StreamWriter file = new System.IO.StreamWriter("d:\\test.txt"); Process [] curentProcess= Process.GetProcesses(); foreach(Process p in curentProcess) file.WriteLine(p.ProcessName); file.Close(); } Regards, Satya
-
Hi, I am trying find the services which are running on my machine on polling basis, and I am trying write this to a file before shutdown. I am trying to do this using a service, I am writing the code for file writing in the OnStop() method of the service. The problem is my service starts and stops immediately. Why this is happening?? Code Snippet: OnStop() { System.IO.StreamWriter file = new System.IO.StreamWriter("d:\\test.txt"); Process [] curentProcess= Process.GetProcesses(); foreach(Process p in curentProcess) file.WriteLine(p.ProcessName); file.Close(); } Regards, Satya
SatyaDY wrote: my service starts and stops immediately Your service does not even reach OnStop(), the problem is Main() or in OnStart(). To locate the failure, check the event log. Are there any exception messages from your service? If not, you can write a log file during OnStart(), to see where the service stops.
-
Hi, I am trying find the services which are running on my machine on polling basis, and I am trying write this to a file before shutdown. I am trying to do this using a service, I am writing the code for file writing in the OnStop() method of the service. The problem is my service starts and stops immediately. Why this is happening?? Code Snippet: OnStop() { System.IO.StreamWriter file = new System.IO.StreamWriter("d:\\test.txt"); Process [] curentProcess= Process.GetProcesses(); foreach(Process p in curentProcess) file.WriteLine(p.ProcessName); file.Close(); } Regards, Satya
ummm... I don't really have a solution to your problem, but I think I see a problem with your service. Basically, in order for your service to work, it has to be the first service to stopped during shutdown, else the GetProcess Method won't return those processes stopped before hand.
"if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.
-
SatyaDY wrote: my service starts and stops immediately Your service does not even reach OnStop(), the problem is Main() or in OnStart(). To locate the failure, check the event log. Are there any exception messages from your service? If not, you can write a log file during OnStart(), to see where the service stops.
check the event log Yeah, I checked the event log, it's having entries for start and stop. When I comment the code, for file opening and writing, I find it running without any problem. How the file writing of the process names giving the problem I couldn't get. Regards, Satya
-
ummm... I don't really have a solution to your problem, but I think I see a problem with your service. Basically, in order for your service to work, it has to be the first service to stopped during shutdown, else the GetProcess Method won't return those processes stopped before hand.
"if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.
-
I think you are correct. Because the GetProcess couldn't get the Processes, file writing is also failing and the service is stopping immediately. Can we give priority (for making it first to stop)?? Regards, Satya
I'm not too familiar with services, but you might try and see doing this
Thread th = Thread.CurrentThread; th.Priority = ThreadPriority.Highest;
during onStart if it will help. :~
"if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.
-
I'm not too familiar with services, but you might try and see doing this
Thread th = Thread.CurrentThread; th.Priority = ThreadPriority.Highest;
during onStart if it will help. :~
"if you vote me down, I shall become more powerful than you can possibly imagine" - Michael P. Butler.
Whoa there Tex! Really bad idea. This will not give priority to the service to be shutdown first. As a matter of fact, you'll just end up slowing down the rest of the system doing this... You can't give priority to any service to shutdown first. You might want to try overriding WndProc and watching for the WM_QUERYENDSESSION message. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
Whoa there Tex! Really bad idea. This will not give priority to the service to be shutdown first. As a matter of fact, you'll just end up slowing down the rest of the system doing this... You can't give priority to any service to shutdown first. You might want to try overriding WndProc and watching for the WM_QUERYENDSESSION message. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome