Topshelf便捷创建Windows服务
结合Quartz.net学习,前提已经创建了一个定时任务,可见 《定时调度框架:Quartz.net》 (基于配置文件形式)
首先引用Topshelf.dll
自定义服务TestService,继承ServiceControl,实现方法。
public class TestService : ServiceControl
{
private readonly IScheduler scheduler;
public TestService()
{
scheduler = StdSchedulerFactory.GetDefaultScheduler(); //创建一个作业调度
}
public bool Start(HostControl hostControl)
{
scheduler.Start();
return true;
} public bool Stop(HostControl hostControl)
{
scheduler.Shutdown();
return true;
}
public bool Continue(HostControl hostControl)
{
scheduler.ResumeAll();
return true;
} public bool Pause(HostControl hostControl)
{
scheduler.PauseAll();
return true;
}
在Main中输入:
static void Main(string[] args)
{ HostFactory.Run(x =>
{ x.Service<TestService>(); x.SetDescription("QuartzDemo服务描述");
x.SetDisplayName("QuartzDemo服务显示名称");
x.SetServiceName("QuartzDemo服务名称");
});
}
可以安装服务(程序所在目录下cmd执行),或可以用记事本输入改为bat格式,放在程序目录,双击执行
- 安装:TopshelfDemo.exe install
- 启动:TopshelfDemo.exe start
- 卸载:TopshelfDemo.exe uninstall


若在安装过程中,报“ service can only be installed as an administrator”
找到**.exe文件,属性-》兼容性-》勾选以管理员身份运行即可
Topshelf便捷创建Windows服务的更多相关文章
- TopShelf框架创建Windows服务作为Remoting的宿主案例:
1.创建服务 using System; using System.Collections.Generic; using System.Linq; using System.Text; using S ...
- 使用Topshelf创建Windows服务
概述 Topshelf是创建Windows服务的另一种方法,老外的一篇文章Create a .NET Windows Service in 5 steps with Topshelf通过5个步骤详细的 ...
- [Solution] Microsoft Windows 服务(2) 使用Topshelf创建Windows服务
除了通过.net提供的windows服务模板外,Topshelf是创建Windows服务的另一种方法. 官网教程:http://docs.topshelf-project.com/en/latest/ ...
- Topshelf创建Windows服务
使用Topshelf创建Windows服务 概述 Topshelf是创建Windows服务的另一种方法,老外的一篇文章Create a .NET Windows Service in 5 steps ...
- 【第三方插件】使用Topshelf创建Windows服务
概述 Topshelf是创建Windows服务的另一种方法,老外的一篇文章Create a .NET Windows Service in 5 steps with Topshelf通过5个步骤详细的 ...
- 使用Topshelf组件 一步一步创建 Windows 服务
我们先来介绍一下使用它的好处,以下论述参考自其他大神. topshelf是创建windows服务的一种方式,相比原生实现ServiceBase.Install.Installer更为简单方便, 我们只 ...
- 使用Topshelf创建Windows服务[转载]
概述 Topshelf是创建Windows服务的另一种方法,老外的一篇文章Create a .NET Windows Service in 5 steps with Topshelf通过5个步骤详细的 ...
- 使用Topshelf 5步创建Windows 服务 z
使用Topshelf创建Windows 服务简要的介绍了创建Windows服务的另一种方法,老外的一篇文章Create a .NET Windows Service in 5 steps with T ...
- 使用 Topshelf 结合 Quartz.NET 创建 Windows 服务
Ø 前言 之前一篇文章已经介绍了,如何使用 Topshelf 创建 Windows 服务.当时提到还缺少一个任务调度框架,就是 Quartz.NET.而本文就展开对 Quartz.NET 的研究,以 ...
随机推荐
- Java项目 打war包方法
我们可以运用DOS命令来手工打war包: 首先,打开DOS命令行,敲入"jar",我们发现它提示不是内部或外部的命令这样的错误,这时八成是你的JAVA环境没有配置好,我们可以用JA ...
- 云计算——Google App Eng…
云计算--Google App Engine(一) 编者:王尚 2014.04.12 20:20 介绍:Google App Engine提供一套开发组件让用户轻松的在本地构建和调试网络应用,之后能让 ...
- 30. leetcode 121. Best Time to Buy and Sell Stock
121. Best Time to Buy and Sell Stock Say you have an array for which the ith element is the price of ...
- Uva 679 Dropping Ballls 二叉树的编号
这个程序常规处理起来数据量很大,I可以高达2^D-1 /* ....... */ 里面的代码块据此避免了开太大的数组 做太多的循环 #include<cstdio> #include< ...
- 之前同事问到的一道python题目
Python面试题 之前同事问了一道Python题目如下,暂时归类为面试题 题目:把类似'123.456'的字符串转换成浮点型数据 方法一: >>> print '{:.3f}'.f ...
- struts2增删改查---layer---iframe层
在这里写一下struts2中的简单的增删改查 struts.xml中的配置 <?xml version="1.0" encoding="UTF-8" ?& ...
- 转换Json中的时间戳为标准时间格式
//出自http://www.cnblogs.com/ahjesus function ConvertJSONDateToJSDate(jsonDate) { /// <su ...
- pwntools使用简介2
大致框架 官网的一个简单样例 from pwn import * context(arch = 'i386', os = 'linux') r = remote() # EXPLOIT CODE GO ...
- InnoDB: ERROR: the age of the last checkpoint
--InnoDB: ERROR: the age of the last checkpoint ---------------------------------------------------- ...
- Python 第七天
OOP 面向对象编程--Object Oriented Programming,简称OOP,是一种程序设计思想.在Python中,所有数据类型都可以视为对象,当然也可以自定义对象.自定义的对象数据类型 ...