小编Top*_*erz的帖子

强制使用TopShelf服务的单个实例

我正在使用TopShelf来托管我的Windows服务.这是我的设置代码:

static void Main(string[] args)
{
    var host = HostFactory.New(x =>
    {
        x.Service<MyService>(s =>
        {
            s.ConstructUsing(name => new MyService());
            s.WhenStarted(tc => tc.Start());
            s.WhenStopped(tc => tc.Stop());
        });

        x.RunAsLocalSystem();
        x.SetDescription(STR_ServiceDescription);
        x.SetDisplayName(STR_ServiceDisplayName);
        x.SetServiceName(STR_ServiceName);
    });

    host.Run();
}
Run Code Online (Sandbox Code Playgroud)

我需要确保只有一个应用程序实例可以同时运行.目前,您可以同时将其作为Windows服务和任意数量的控制台应用程序启动.如果应用程序在启动期间检测到其他实

我真的很喜欢基于互斥的方法,但不知道如何使用TopShelf.

c# windows-services single-instance topshelf

4
推荐指数
1
解决办法
1450
查看次数

标签 统计

c# ×1

single-instance ×1

topshelf ×1

windows-services ×1