Windows service 學習

來源:互聯網
上載者:User

標籤:des   blog   http   os   io   for   art   cti   

最近看了看windows service,

1. 找到了一個文章: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 "Interact with Desktop" option is not supported by Microsoft in Windows Vista and newer. So use it wisely and redesign your app if there is a solid chance that your service can be installed on Vista or Server 2008.

應該是因為這個原因:我在Win7中安裝了一個windows service, 這個windows service的主要功能是啟動一個windows Form app. 當啟動這個service的時候,總是會報這個錯誤:
This problem occurs when a program is 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 way to debug the windows service:
 1). Modify "Output type" to "Windows Application" in 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);
            }
        }

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.