码迷,mamicode.com
首页 > Windows程序 > 详细

Windows service 学习

时间:2014-07-28 15:39:23      阅读:269      评论:0      收藏:0      [点我收藏+]

标签: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);
            }
        }

 

Windows service 学习,布布扣,bubuko.com

Windows service 学习

标签:des   blog   http   os   io   for   art   cti   

原文地址:http://www.cnblogs.com/Ruli/p/3873040.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!