`

C# 书写window简单服务

    博客分类:
  • C#
 
阅读更多

 

 

代码如下:

 

using System.ComponentModel;

using System.Configuration.Install;

using System.ServiceProcess;

 

 

namespace WindowsService1

{

    [RunInstaller(true)]

    public partial class InstallerService : Installer

    {

        private ServiceProcessInstaller process;

        private ServiceInstaller service;

 

        public InstallerService()

        {

            process = new ServiceProcessInstaller();

            process.Account = ServiceAccount.LocalSystem;

            service = new ServiceInstaller();

            service.ServiceName = "SimegyServiceTest";

            Installers.Add(process);

            Installers.Add(service);

        }

    }

}

 

 

using System;

using System.Collections.Generic;

using System.Linq;

using System.ServiceProcess;

using System.Text;

 

namespace WindowsService1

{

    static class Program

    {

        /// <summary>

        /// The main entry point for the application.

        /// </summary>

        static void Main()

        {

            ServiceBase[] ServicesToRun;

            ServicesToRun = new ServiceBase[] 

new Service1() 

};

            ServiceBase.Run(ServicesToRun);

        }

    }

}

 


 

 

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Diagnostics;

using System.Linq;

using System.ServiceProcess;

using System.Text;

using System.Security.Cryptography;

 

namespace WindowsService1

{

    public partial class Service1 : ServiceBase

    {

        public Service1()

        {

            InitializeComponent();

            this.CanPauseAndContinue = true;

            this.CanShutdown = true;

            this.CanHandleSessionChangeEvent = false;

            this.ServiceName = "SimegyService_Test";

        }

 

 

        protected override void OnStart(string[] args)

        {

           // System.Threading.Thread.Sleep(5 * 1000 * 60);

        }

 

        protected override void OnStop()

        {

        }

    }

}


 

 

分享到:
评论

相关推荐

    演示C#的MVC模式

    环境:Window XP professinal, .Net Framework 2.0, .NetFramework 2.0 SDK, Notepad, SQL Server 2000数据库 ...所有源代码是按Java的风格书写,并且几乎一行注释一行代码,它是复习C#知识的好东东。

    C# 手写输入控件 InkTextBox

    默认情况下,当用户停止书写时,InkTextBox会尝试自动识别并替换墨迹。如果需要手动控制识别,可以监听`StrokeCollected`事件,然后调用`InkRecognizerContext`的`RecognizeAsync`方法进行识别。 **4. 墨迹管理** ...

    C# 命名规范、代码书写格式(含图表)

    在C#编程中,遵循一套良好的命名规范和代码书写格式是非常重要的,这有助于提高代码的可读性,降低维护成本,以及保持团队间的统一风格。本文将详细阐述C#中的命名规范、代码格式以及相关图表所示的规则。 一、命名...

    JSON Web Token (前端与后端对话密钥生成文件)

    token 生成文件,用于前后端数据传输时发送的密钥(暗语)。...生成公钥 // window电脑不支持 openssl 代码,使用 git 提供的控制台书写即可 - openssl rsa -in private.key -pubout -outform PEM -out public.key

    PB 12.5的新功能介绍文档

    PowerBuilder 12.5在.NET语言方面进行了多项增强,包括对C#和VB.NET的深度集成,以及对最新.NET标准的支持,这使得开发人员可以更灵活地选择编程语言并充分利用.NET平台的优势。 #### WPFRuntime和WPF Debugger ...

    ExtAspNet_v2.3.2_dll

    -增加示例(iframe/parent_postback_run3.aspx),如何通过简单的Javascript代码回发父页面(feedback:eroach)。 -修正一些书写错误(feedback:bmck)。 -从Region控件中删除SplitColor属性,增加CollapseMode, ...

    ExtAspNet v2.2.1 (2009-4-1) 值得一看

    -如何自定义Javascript脚本和C#处理函数来响应键盘事件。 -为Tree增加AutoLeafIdentification属性。 -增加示例(tree_auto_leaf_identification.aspx)(feedback:wdrabbit)。 +2009-11-17 v2.1.4 -修正...

    web数据库

    - **标签书写规则**: 标签名称和 `之间不能有任何空格或其他字符,例如正确的写法应该是 `&lt;p&gt;` 而不是 `&lt; p&gt;`。 #### 2. VBScript基础 - **字符串操作**: - `Left(string, length)`: 返回字符串左边指定长度的子串...

Global site tag (gtag.js) - Google Analytics