基本信息
源码名称:TopShelf:windows服务开发框架
源码大小:4.79M
文件格式:.zip
开发语言:C#
更新时间:2019-02-28
   友情提示:(无需注册或充值,赞助后即可获取资源下载链接)

     嘿,亲!知识可是无价之宝呢,但咱这精心整理的资料也耗费了不少心血呀。小小地破费一下,绝对物超所值哦!如有下载和支付问题,请联系我们QQ(微信同号):78630559

本次赞助数额为: 2 元 
   源码介绍

topshelf

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Topshelf;
using Topshelf.Logging;
using System.Timers;

namespace TopShelf2
{
    class Program
    {
        static void Main(string[] args)
        {                                                              
            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("Sample Topshelf Host");        
                x.SetDisplayName("Stuff");                       
                x.SetServiceName("Stuff");                       
            });
        }
    }




    public class TownCrier
    {
        readonly Timer _timer;
        public TownCrier()
        {
            _timer = new Timer(1000) { AutoReset = true };
            _timer.Elapsed  = ((sender, eventArgs) => {
                Console.WriteLine("It is {0} and all is well", DateTime.Now);
                Console.ReadKey();
            });
        }
        public void Start() { _timer.Start(); }
        public void Stop() { _timer.Stop(); }
    }
}