Windows Service Learning

Source: Internet
Author: User

Recently looked at Windows service,

1. A post was found: http://blog.csdn.net/knight94/article/details/627298

2. At the end of the link http://www.cnblogs.com/Googler/archive/2013/07/23/3208354.html, there is a sentance:the "Inter Act with Desktop "option was not a supported by Microsoft in Windows Vista and newer. So use it wisely and redesign your app if there are a solid chance that your service can being installed on Vista or Server 20 08.

That's why: I installed a Windows service in Win7, the main feature of this Windows service is to start a Windows Form app. This error is always reported when the service is started:
This problem occurs if a program was not fully compatible with Windows. Please contact the program or device manufacturer (s) for more information. In the Interactive Services Detection dialog.

3. Windows Service Properties:

Log on---> Allow service to interact with desktop.

4. Debug Windows Service:
There is a-to-debug the Windows service:
1). Modify "Output type" to "Windows application" on the Serivce Project Property tab page.
2). In the Main (), to add the following code in Program.cs:

        static void Main ()
        {
            if (environment.userinteractive)
            {
                 string[] args = {"", ""};
                Service service = New Service ();
                Service. Start (args);
           }

            Else
             {
                 servicebase[] ServicesToRun;

                //more than One user Service may run within the same process. To add
                // Another service to this process, change the following line to
                //Create a second service object. For example,
               //
                ServicesToRun = New servicebase[] {new Service1 (), New MySecondUserService ()};
               //
                 ServicesToRun = new Servicebase[] {new Service ()};

Servicebase.run (ServicesToRun);
}
}

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.