关于TopShelf 描述:

Topshelf is a framework for hosting services written using the .NET framework. The creation of services is simplified, allowing developers to create a simple console application that can be installed as a service using Topshelf. The reason for this is simple: It is far easier to debug a console application than a service. And once the application is tested and ready for production, Topshelf makes it easy to install the application as a service.

1、ok,首先使用VS 建立一个控制台 程序,使用Nuget 搜索 TopShelf 引用 TopShelf 和 TopShelf.Log4Net

2、写入代码:

 public class TownCrier
{
readonly Timer _timer;
public TownCrier()
{
_timer = new Timer() {AutoReset = true};
_timer.Elapsed += (sender, eventArgs) => Console.WriteLine("It is {0} an all is well", DateTime.Now);
}
public void Start() { _timer.Start(); }
public void Stop() { _timer.Stop(); }
} public class Program
{
public static void Main()
{
HostFactory.Run(x =>
{
x.Service<TownCrier>(s =>
{
s.ConstructUsing(name=> new TownCrier());
s.WhenStarted(tc => tc.Start()); //指定此服务的启动函数
s.WhenStopped(tc => tc.Stop()); //指定此服务的终止函数
});
x.RunAsLocalSystem(); x.SetDescription("这是一个测试的服务 作用就是控制台输出~~"); // 服务描述
x.SetDisplayName("_Rufus_Test_Winservices"); //服务显示名字
x.SetServiceName("_Rufus_Test_winServices"); //服务名字
});
}
}

3、编译

4、找到你编译成功的exe程序 执行cmd命令 (ps: 需要管理员权限)

XXXXX install    (xxxx是你编译的程序名 例如 我的为 WinServerTest install)

5、现在 查看 服务管理器 发现  _Rufus_Test_Winservices  已经注册到 里面 了,手动启动这个 服务即可。

使用TopShelf轻松开发Window服务的更多相关文章

  1. c# 开发window服务

    http://jingyan.baidu.com/article/fa4125acb71a8628ac709226.html 安装 cmd 输入 InstallUtil.exe E:\TestApp\ ...

  2. .NET Window服务启动又马上停止,报错IO.FileNotFoundException

    最近公司需要开发一个Window服务推送系统,读取MongoDB写入消息队列,推送到各终端平台 但是在开发完成,最后的部署阶段,选中服务右击启动 看似正常,服务显示已启动(但实质已经被终止,因为Win ...

  3. 使用Topshelf 开发windows服务

    在业务系统中,我们为了调度一些自动执行的任务或从队列中消费一些消息,所以基本上都会涉及到后台服务的开发.如果用windows service开发,非常不爽的一件事就是:调试相对麻烦,而且你还需要了解 ...

  4. 使用Topshelf开发Windows服务、log4net记录日志

    开发windows服务,除了在vs里新建服务项目外(之前有写过具体开发方法,可点击查看),还可以使用Topshelf. 不过使用topshelf需要.netframework 4.5.2版本,在vs2 ...

  5. topshelf 开发windows 服务资料

    官方配置 http://docs.topshelf-project.com/en/latest/configuration/config_api.html#service-start-modes to ...

  6. C# DateTime的11种构造函数 [Abp 源码分析]十五、自动审计记录 .Net 登陆的时候添加验证码 使用Topshelf开发Windows服务、记录日志 日常杂记——C#验证码 c#_生成图片式验证码 C# 利用SharpZipLib生成压缩包 Sql2012如何将远程服务器数据库及表、表结构、表数据导入本地数据库

    C# DateTime的11种构造函数   别的也不多说没直接贴代码 using System; using System.Collections.Generic; using System.Glob ...

  7. 通过TopShelf快速开发服务程序

    我之前在文章中介绍过使用NSSM将exe封装为服务,这种方式我个人是比较喜欢的,一来原始文件不受服务的开发约束,二来也可以提供简单的日志系统.线程守护等功能,是我个人比较倾向的行为.但是,有的场景下, ...

  8. VS轻松开发Node.js应用

    PTVS开发团队又开发出一款可以在VS里编写Node.js应用程序的插件--NTVS(Node.js Tools for Visual Studio),开发者可以在VS里轻松开发Node.js应用. ...

  9. C# 编写Window服务基础(一)

    一.Windows服务介绍: Windows服务以前被称作NT服务,是一些运行在Windows NT.Windows 2000和Windows XP等操作系统下用户环境以外的程序.在以前,编写Wind ...

随机推荐

  1. ie对行高line-height的诡异解释

    切 游戏页面真地是要求太精细了,做按钮的时候我犯了一个错误,居然用span的内联元素的行高和padding来控制,虽然有很多好处,但是IE对 line-height的解释导致按钮经常下边会缺一小部分, ...

  2. A标记点击后去掉虚线

    没加时,谷歌无虚线,但ie有虚线. 加上这句,所有的a标签点击都没有虚线了. a {outline: none;} a:active {star:expression_r(this.onFocus=t ...

  3. HDU 4267-A Simple Problem with Integers(多个BIT)

    题意: 2种操作 1 a b k c 在区间[a,b]中的(i-a)%k==0的位置i上的数+c 2 a 查询位置a的值 输出每次查询的值 分析: 开始想到多维的线段树,但比较麻烦,看了题解才知道,用 ...

  4. 酷派8150S(移动定制版)可用的第三方Recovery备份数据、刷机并精简系统内置APK经验

    希望使用的第三方Recovery下载地址: ClockworkMod ROM Manager - Recoveries http://clockworkmod.com/rommanager 适配的型号 ...

  5. 开通GitHub以及使用笔记

    把小游戏的代码和博客迁移到GitHub上,路径是:https://github.com/GAMTEQ,欢迎访问 以下是使用GITHUB的一些命令 504  cd code 506  mkdir Fai ...

  6. python 入门实践之网页数据抓取

    这个不错.正好入门学习使用. 1.其中用到 feedparser: 技巧:使用 Universal Feed Parser 驾驭 RSS http://www.ibm.com/developerwor ...

  7. 在eclipse中配置spark 0.9.1源码的开发环境

    一.准备工作: 1.下载release版spark 0.9.1,本次用的版本是spark-0.9.1-bin-cdh4. 2.下载scala IDE 3.0.2,这个版本ide的支持scala 2.1 ...

  8. HDU-4734 F(x) 数位DP

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4734 注意到F(x)的值比较小,所以可以先预处理所有F(x)的组合个数.f[i][j]表示 i 位数时 ...

  9. ES6学习(1)——如何通过babel将ES6转化成ES5

    使用babel编译ES6 babel是一个工具,可以通过多个平台,让js文件从ES6转化成ES5,从而支持一些浏览器并未支持的语法. Insall babel $ sudo npm install b ...

  10. ocp 1Z0-051 106-140题解析

    106. Examine the data inthe LIST_PRICE and MIN_PRICE columns of the PRODUCTS table: LIST_PRICE MIN_P ...