Windows Service FAQs

Source: Internet
Author: User

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.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.