1. The most common problem of OnStart () is the execution time of OnStart (). If the SCM takes more than 30 seconds, it is arbitrarily considered that the service cannot be started. Therefore, it is recommended to put it in the thread for execution.
2. the most painful problem in debugging: paste the Code directly and write the following code in mian:
static void Main()
{
System.ServiceProcess.ServiceBase[] ServicesToRun;
ServicesToRun = new System.ServiceProcess.ServiceBase[] { new Watcher() };
System.ServiceProcess.ServiceBase.Run(ServicesToRun);
//#region //Console.WriteLine("Console"); //Watcher watcher = new Watcher(); //watcher.OnStart(null); //Console.ReadLine(); //watcher.OnStop(); //watcher.Dispose(); //#endregion }
Take a good look at the code. I like to deregister the program to switch between debugging and release versions. You can also use # if or input parameters to determine whether to switch between debugging and release versions. This may be difficult. It is recommended that you register and run it again (I have just learned ^ _ ^, but I am not honest ).
3. register the service with C: \ Windows \ Microsoft. run installutil.exe under the NET \ Framework \ v2.0.50727directory (in the command line: Current Directory => InstallUtil [-u] service name .exe ).
If you want to install it directly, you can find the Windows service installation, which has the installutil.exe version, and the images are illustrated.
4. functional limitations: in other words, the service is almost a Trojan, and the opposite is similar. You can't see it, huh, so it has a lot of permissions, but you can put it in other programs, and then control the communication through the service.
5. screenshot problem: Ah, I want to do something bad for the first time programming. Haha, then I will report an error, but it is correct on the console. The reason is very simple. The service has no interface, so it has nothing to do with the desktop. Of course, you cannot take screenshots.
6. Execution directory problem: C: \ Windows \ System32 is its execution directory, not the directory where your program is located.
So many kids who wish to use windows Services for the time being, I would like to share with you all the problems that have been encountered, not encountered, solved, and not solved ^ _ ^. Thank you very much.