关于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. H264码流打包分析(精华)

    H264码流打包分析 SODB 数据比特串-->最原始的编码数据 RBSP 原始字节序列载荷-->在SODB的后面填加了结尾比特(RBSP trailing bits 一个bit“1”)若 ...

  2. 【转】iOS类似Android上toast效果

    原文网址:http://m.blog.csdn.net/article/details?id=50478737 做过Android开发的人都知道toast,它会在界面上显示一排黑色背景的文字,用于提示 ...

  3. 【转】Android Studio简单设置

    原文网址:http://ask.android-studio.org/?/article/14 Android Studio 简单设置 界面设置 默认的 Android Studio 为灰色界面,可以 ...

  4. strleng函数和filterHtml函数的据悉

    紧接着“CKEditor如何统计文字数量”,我想稍微说下,下面就filterHtml就是用来过滤全部html标签的. /** *过滤html标签 */ function filterHtml(s){ ...

  5. Spring各jar包的作用(转载)

    spring.jar是包含有完整发布的单个jar 包,spring.jar中包含除了spring-mock.jar里所包含的内容外其它所有jar包的内容,因为只有在开发环境下才会用到 spring-m ...

  6. UIButton 设置为圆形,并且使用图片(UIImage)当做背景

    -(UIButton *)shareButtonWithIcon:(NSString *)iconName { UIButton *button = [UIButtonbuttonWithType:U ...

  7. NiuTrans 日记 1

    这些天把东北大学自然语言实验室的NiuTrans 系统搭建并按照例子将短语系统运行了一遍,写这个日记主要是为了以后能提醒自己在这其中遇到的问题. 环境:短语系统我是windows和linux都运行了, ...

  8. ubuntu开发软件的安装

    今天下午发现ubuntu12.04坏了,无奈只能重新安装,建议读者配置自己的ubuntu后备份一个,免得坏了重新安装,花了两个小时才把ubuntu的交叉环境弄好,其中搭建了tptp通信协议,还有arm ...

  9. springmvc的一些优化设置

    1.配置文件的优化: 无需使用 <bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotatio ...

  10. MSI/MSI-X

    MSI PCI2.2规范引进了MSI作为传统的基于线的中断的替代方案.MSI允许设备通过向一个特定的地址写入一个特定的值来允许中断,而不是使用一个专有的引脚来触发中断.注意消息的目的地址和消息数据被当 ...