C#中如何建立Windows服務
来源:互联网 发布:java中什么是构造函数 编辑:程序博客网 时间:2024/05/10 02:50
在建立項目時﹐選擇Windows服務后就產生一個繼承自System.ServiceProcess.ServiceBase的類﹐主要在OnStart和OnStop中添加執行和釋放的方法,注意CanPauseAndContinue是可以設置是否允許中止服務的. 最關鍵的是安裝服務﹐直接用InstallUtil是不行的﹐還要在項目中添加一個Installer的繼承類。方法如下﹕
windows服务安装类代码
using System.Collections;
using System.Configuration.Install;
using System.ServiceProcess;
using System.ComponentModel;
namespace WindowsService1
{
/// <summary>
/// myInstall 的摘要说明。
/// </summary>
///
[RunInstaller(true)]
public class myInstall : Installer
{
private ServiceInstaller serviceInstaller;
private ServiceProcessInstaller processInstaller;
public myInstall()
{
processInstaller = new ServiceProcessInstaller();
serviceInstaller = new ServiceInstaller();
processInstaller.Account = ServiceAccount.LocalSystem;
serviceInstaller.StartType = ServiceStartMode.Automatic;
serviceInstaller.ServiceName = "WindowsService1"; //WindowsService1是你的服務類名
Installers.Add(serviceInstaller);
Installers.Add(processInstaller);
}
}
}
- C#中如何建立Windows服務
- 如何在VS2010中建立C#三层结构
- C#中windows程序全屏如何设置
- C#中 如何创建Windows服务?
- C#建立了一个windows程序,如何防止多个程序实例运行?
- C# Windows Form中如何设置datagrid的各行颜色.
- C#中如何取得并使用Windows系统图标
- c#中如何跨线程调用windows控件
- c#中如何跨线程调用windows窗体控件?
- c#中如何跨线程调用windows窗体控件?
- c#中如何跨线程调用windows窗体控件
- C#中如何安装和卸载【Windows服务】?
- C# 如何在 Windows 文件系统中添加自定义右键菜单
- c#中如何跨线程调用windows窗体控件?
- c#中如何跨线程调用windows窗体控件
- c#中如何跨线程调用windows窗体控件?
- c#中如何截取Windows消息来触发自定义事件
- c#中如何跨线程调用windows窗体控件?
- .Net中的反射使用入门
- js模仿flash菜单-- 超酷
- SQLServer数据库同步准实时方案
- Linux内核和传统Unix内核的比较
- 一个很漂亮的日历
- C#中如何建立Windows服務
- Dreamweaver构建Blog全程实录
- 基于GUI编程时,如何在客户端与服务器之间传递对象
- 删除的2次确认 ItemDataBound
- 创建动态代理服务
- MFC程序框架剖析
- Visual Basic COM基础讲座之(二)
- PHP操作MYSQL数据库类
- Oracle Sql优化笔记