使用Topshelf 5步创建Windows 服务 z
使用Topshelf创建Windows 服务简要的介绍了创建Windows服务的另一种方法,老外的一篇文章Create a .NET Windows Service in 5 steps with Topshelf通过5个步骤详细的介绍使用使用Topshelf创建Windows 服务。Topshelf是一个开源的跨平台的宿主服务框架,支持Windows和Mono,只需要几行代码就可以构建一个很方便使用的服务宿主。
1、Topshelf的代码托管在http://topshelf-project.com/,可以在这里下载到最新的代码。
2、使用Visual Studio创建一个控制台应用程序引用程序集TopShelf.dll 合log4net.dll 。
3、创建一个简单的服务类,里面包含两个方法Start和Stop,这个服务只是演示代码,所以我们每隔5秒输出一个日志。
using System.Timers;
using log4net;
namespace SampleWindowsService
{
public class SampleService
{
private Timer _timer = null;
readonly ILog _log = LogManager.GetLogger(typeof(SampleService));
public SampleService()
{
double interval = 5000;
_timer = new Timer(interval);
_timer.Elapsed += new ElapsedEventHandler(OnTick);
}
protected virtual void OnTick(object sender, ElapsedEventArgs e)
{
_log.Debug("Tick:" + DateTime.Now.ToLongTimeString());
}
public void Start()
{
_log.Info("SampleService is Started");
_timer.AutoReset = true;
_timer.Enabled = true;
_timer.Start();
}
public void Stop()
{
_log.Info("SampleService is Stopped");
_timer.AutoReset = false;
_timer.Enabled = false;
}
}
}
using log4net.Config;
using Topshelf;
namespace SampleWindowsService
{
class Program
{
static void Main(string[] args)
{
XmlConfigurator.ConfigureAndWatch(
new FileInfo(".\\log4net.config"));
var host = HostFactory.New(x =>
{
x.EnableDashboard();
x.Service<SampleService>(s =>
{
s.SetServiceName("SampleService");
s.ConstructUsing(name => new SampleService());
s.WhenStarted(tc =>
{
XmlConfigurator.ConfigureAndWatch(
new FileInfo(".\\log4net.config"));
tc.Start();
});
s.WhenStopped(tc => tc.Stop());
});
x.RunAsLocalSystem();
x.SetDescription("SampleService Description");
x.SetDisplayName("SampleService");
x.SetServiceName("SampleService");
});
host.Run();
}
}
}
A WCF calculator in a windows service with TopShelf
WCF service with Topshelf using as a host, log4net as logging tool, and HTML as output
使用Topshelf 5步创建Windows 服务 z的更多相关文章
- 使用Topshelf 5步创建Windows 服务
使用Topshelf创建Windows 服务简要的介绍了创建Windows服务的另一种方法,老外的一篇文章Create a .NET Windows Service in 5 steps with T ...
- 使用 Topshelf 组件一步一步创建 Windows 服务 (2) 使用Quartz.net 调度
上一篇说了如何使用 Topshelf 组件快速创建Windows服务,接下来介绍如何使用 Quartz.net 关于Quartz.net的好处,网上搜索都是一大把一大把的,我就不再多介绍. 先介绍需要 ...
- 使用Topshelf组件 一步一步创建 Windows 服务
我们先来介绍一下使用它的好处,以下论述参考自其他大神. topshelf是创建windows服务的一种方式,相比原生实现ServiceBase.Install.Installer更为简单方便, 我们只 ...
- 使用Topshelf创建Windows 服务
本文转载: http://www.cnblogs.com/aierong/archive/2012/05/28/2521409.html http://www.cnblogs.com/jys509/p ...
- 使用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 结合 Quartz.NET 创建 Windows 服务
Ø 前言 之前一篇文章已经介绍了,如何使用 Topshelf 创建 Windows 服务.当时提到还缺少一个任务调度框架,就是 Quartz.NET.而本文就展开对 Quartz.NET 的研究,以 ...
- 使用 Topshelf 创建 Windows 服务
Ø 前言 C# 创建 Windows 服务的方式有很多种,Topshelf 就是其中一种方式,而且使用起来比较简单.下面使用 Visual Studio Ultimate 2013 演示一下具体的使 ...
随机推荐
- socket、webService、RMI ?
网络七层协议为:物理层.数据链路层.网络层.传输层.会话层.表示层.应用层 webService > RMI > socket RMI比socket更高一点 socket 只是 java在 ...
- spring注解方式在一个普通的java类里面注入dao
spring注解方式在一个普通的java类里面注入dao @Repositorypublic class BaseDaoImpl implements BaseDao {这是我的dao如果在servi ...
- java_常用数据类型转换基础篇
一.java基本数据类型 1.java基本数据类型可分四类八中 第一类:整形:byte.short.int.long 第二类:浮点型:float(单精度) .double(双精度) 第三类:逻辑类型: ...
- Iaas-cloudstack
http://cloudstack.apt-get.eu/systemvm/4.6/ 模板地址 http://cloudstack.apt-get.eu/centos7/4.6/ 代理及管理地址 ht ...
- Ackerman函数
Ackerman函数在许多讲解递归的书中都提到,但似乎又对解题没有太大的意义,暂时不知道了.不过这个东西,是一个数学知识点,暂时收藏于此吧. 查了一下维基百科和百度百科,表面上两个定义不一样,仔细推敲 ...
- OpenJudge计算概论-计算书费
/*============================================== 计算书费 总时间限制: 1000ms 内存限制: 65536kB 描述 下面是一个图书的单价表: 计算 ...
- CSS之column语法
columns column-width:[<length>|auto] 定义每栏的宽度 column-span:1|all 1:只在本栏中显示:all:横跨所有栏目并定位在栏目的Z轴之上 ...
- Mozilla Brick:一个Web组件Polyfill库
Web组件是一个W3C规范,它旨在使Web开发人员能够定义具有非常丰富的视觉效果和高可交互性且易于组合的小组件.Brick库提供了新的自定义HTML标签,从而抽象了用户常用接口模式.在浏览器本身支持类 ...
- JavaScript兼容性问题
Firefox浏览器不支持js的innerText属性:
- 百度ueditor学习使用
1.下载ueditor解压 2. jsp里存放着开发所用到的jar包,导入项目即可 前端页面代码如下: <center> <form action="" meth ...