Windows service 学习

最近看了看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 学习

时间: 2024-08-02 14:55:51

Windows service 学习的相关文章

c# windows 服务学习

用C#做windows服务变得简单对了===按照下面步骤来就行了用C#创建Windows服务(Windows Services)例子服务功能:这个服务在启动和停止时,向一个文本文件中写入一些文字信息. 第一步:创建服务框架 要创建一个新的 Windows 服务,可以从Visual C# 工程中选取 Windows 服务(Windows Service)选项,给工程一个新文件名,然后点击 确定.你可以看到,向导向工程文件中增加WebService1.cs类:其中各属性的含意是: Autolog 是

Android Web Service学习总结(一)

最近学习android平台调用webWebService,学习了一篇不错的博客(http://blog.csdn.net/lyq8479/article/details/6428288),可惜是2011年时的方法,而不适合现在android4.0之后的android版本,所以通过一番学习和研究,总结如下. web Service简介 通俗的理解:通过使用WebService,我们能够像调用本地方法一样去调用远程服务器上的方法.我们并不需要关心远程的那个方法是Java写的,还是PHP或C#写的:我

Windows Workflow学习文档

Windows Workflow学习文档   1     概念 2     Windows Workflow 2.1      .Net Framework 3.0 简介 2.2      Windows Workflow Foundation简介 3     开发环境搭建 4     Workflow模型 4.1      WF中流程模型 4.2      关键概念 5     Activity 5.1      什么是Activity 5.2      Activity的其他概念 5.3  

.Net Remoting的双向通信和Windows Service的宿主服务

原文:.Net Remoting的双向通信和Windows Service的宿主服务 作为微软分布式技术之一的.Net Remoting,从性能.安全等各方面来说都是相对比较稳定的,也是一项比较成熟的分布式技术. 从学习.Net Remoting至今,仅仅只使用了一次这门技术,是在去年的一个IM产品中.最近公司的产品出现了很多问题,服务器.通信接口.网站都陆续被攻击(DDOS).这对于做互联网产业的同行来说就清楚这里面的关系,强大的DDOS攻击可以直接让产品无法正常运营甚至停止运营. 经过一系列

.NET Windows Service

.net包含的内容真的很多,即使从应用上来说. 从来没有接触过windows service的开发,但是需要承接的项目使用到了,于是阅读了一下微软的文档. 总体来说,windows service是一个继承ServiceBase类的应用,通过run方法启动的一个进程(线程?). 通过InstallUtil.exe注册后,就像其他服务一样,出现在services.msc的列表中了. ServiceBase类除了构造函数,关键的是几个事件的处理,OnStart/OnStop等等,感觉有点Androi

Windows service wrapper 初探

Windows 服务包装器(Windows service wrapper),用于把.exe文件注册为windows服务.比如把Nginx.exe注册为windows服务,这样做的好处是,每次启动nginx时不用在命令行中输入命令,而且可以随windows系统启动而启动.不用担心服务器意外重启,服务挂掉. github地址:https://github.com/kohsuke/winsw 下载地址:https://github.com/kohsuke/winsw/releases 目前(2017

C# Windows Service中执行死循环轮询

用C#编写Windows Service时,执行轮询一般有两种方式,一种是用Timer,System.Timers或者是System.Thread下的,这种执行是按时间循环执行,缺点是也许上个执行还没有完成,又开始执行新的. 另一种方式是利用线程,在OnStart里单开一个线程去跑含有死循环结构的函数,这种方式的缺点是,对线程的控制困难,停止服务了,线程还有可能在执行,不过 .Net 4.0+ 给我们提供了 CancellationTokenSource,用来取消正在运行的线程(Task),代码

管理员控制Windows Service

C# 以管理员方式启动Winform,进而使用管理员控制Windows Service 问题起因: 1,) 问题自动分析Windows服务在正常运行时,确实会存在程序及人为原因导致该服务停止.为了在应用程序使用时确保该服务正常运行,于是有了该讨论主题. 2,)一般账户(尽管是管理员组账户)使用c#代码启动服务,依然会抛出异常,因为当前程序启动账户级别并不是管理员级别. 以管理员启动应用程序解决方案及测试: 为了解决程序以管理员组角色启动应用程序,我们需要在应用程序的工程中添加一个“Applica

在Windows Service 2012上安装IIS 8.0 IIS 6

我的目的是在服务器上安装IIS6 ,但是受到这边文章的启发和按照他的步骤,看到了"IIS 6管理兼容性",我的问题就决解了,我这里是因为要安装vss 2005 和u8等比较早期的软件才会遇到这个问题: 下面内容转载自:http://www.zhaomu.com/news/detail-394.html 内容如下: Windows 2012及其自带的IIS 8.0是微软公司新一代的Web服务器软件,和老版本的IIS相比,有很多破天荒的新功能.随着微软宣布不再支持Windows XP操作系