发布:2023/12/7 15:52:22作者:大数据 来源:大数据 浏览次数:493
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
HostFactory.Run(x => { x.RunAsLocalSystem(); x.SetDescription("topshelf测试"); x.SetDisplayName("topshelftest"); x.SetServiceName("topshelftest"); x.Service<TopshelfTest>(s => { s.ConstructUsing(name => new TopshelfTest()); s.WhenStarted(tc => tc.Start()); s.WhenStopped(tc => tc.Stop()); }); }); |
服务类
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
using System; using System.Timers; namespace TopshelfDemo { public class TopshelfTest { readonly Timer timer; public TopshelfTest() { timer = new Timer(1000) { AutoReset = true }; timer.Elapsed += (sender, eventArgs) => { Run(); }; } public void Start() { timer.Start(); } public void Stop() { timer.Stop(); } public static void Run() { Console.WriteLine("hello TopShelf"); } } } |
使用管理员进入cmd进入相应的文件夹位置
注册:TopshelfDemo.exe install
启动:TopshelfDemo.exe start
卸载:TopshelfDemo.exe uninstall
© Copyright 2014 - 2025 柏港建站平台 ejk5.com. 渝ICP备16000791号-4