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 的研究,以 ...
随机推荐
- CPUImageRGBFilter 实现
参考自: https://github.com/BradLarson/GPUImage GPUImageRGBFilter: Adjusts the individual RGB channels o ...
- C# Process.Start()
本文转自:http://webcache.googleusercontent.com/search?q=cache:v4Sh6GlfJPYJ:blog.csdn.net/czw2010/article ...
- ajax执行顺序问题
在一个函数里,执行顺序是先传所有的值到指定url,然后再返回所有的success 解决方法:将ajax改成异步 aysnc:false
- .NET Exceptionless 日志收集框架本地环境搭建
一.简介 Exceptionless 是一个开源的实时的日志收集框架,它可以应用在基于 ASP.NET,ASP.NET Core,Web Api,Web Forms,WPF,Console,MVC 等 ...
- GitLab Development Kit 环境搭建
在公司内网服务器上面搭建gdk环境,踩了很多坑,历时四五天(中间涉及申请开通固定外网),整理如下: 总览: 操作系统:redhat 6.3 参考文档:https://gitlab.com/gitlab ...
- [算法题] Remove Duplicates from Sorted Array
题目内容 本题来源于LeetCode Given a sorted array, remove the duplicates in place such that each element appea ...
- 【NO.14】jmeter-处理结果
在1台测试机上面处理测试结果并没啥,比较麻烦的是合并2台测试机的测试结果. 首先说说,为什么我们需要使用2台(甚至3台.4台)测试机对服务器发送大量的请求呢?说白了就是测试机配置太弱了,服务器太牛逼. ...
- 在Android中使用枚举注解而不是枚举
Enums often require more than twice as much memory as static constants. You should strictly avoid us ...
- ASP.NET MVC 创建 Area 以及使用
此博客全乘抄袭,只为以后自己能再次用到 参考链接 http://www.cnblogs.com/willick/p/3331519.html ASP.NET MVC允许使用 Area(区域)来组织We ...
- 《DSOD:Learning Deeply Supervised Object Detectors from Scratch》翻译
原文地址:https://arxiv.org/pdf/1708.01241 DSOD:从零开始学习深度有监督的目标检测器 Abstract摘要: 我们提出了深入的监督对象检测器(DSOD),一个框架, ...