I have 3 Windows Service Question
-
Is WS can work in background ? Is it possible to do some job every 2 minutes ? (if yes, can I get some help ?)
-
How can I install WS in simple way ? (not with Installutil.exe …….)
-
How can I run .exe file from Windows service ?
I’ve tried this way:
System.Diagnostics.Process G = new Process(); G.StartInfo.FileName = @'d:\demo.exe'; G.Start();
but it didn’t work.
Yes a windows service can and does work in the background. To do the same job every 2 minutes use the system.Timer class and put your code in the onElapsed event. I’ve recently created this type of service and found there are two types of Timer you can use, make sure you use the correct one or you will not find the onElapsed event.
I’ve not tried installing without the InstallUtil.exe but I do have a .bat file that I use which is run as part of my main application installation.
Your follow-up question on running an .exe from a Windows Service, to run an .exe from a Windows Service I have used:
Remember that the executable will run at the same level as the service which means it can’t display anything on the desktop. If you are expecting to see any window open or the .exe requires any user input then you will be disappointed and the .exe may wait indefinitely. (I found this link Launch external programs helped and there is also this question on SO – Launching an Application (.EXE) from C#)