首页 > 解决方案 > C# 错误:无法启动服务。该服务的一个实例已经在运行

问题描述

想知道是否有人可以帮助我解决这个问题,我是使用服务的新手,所以非常感谢一些帮助。Bascailly 我想要做的是通过创建多个不同的线程并调用创建服务的 ThreadHandler 方法来运行服务的多个实例。

“服务无法启动。服务实例已在运行”

当前发生的情况是,当我启动服务时,第一个实例工作正常,但检查事件日志我看到有关第二个实例的此错误

//Creates multiple thread instances
foreach (ThreadManagerPoco threadManager in ThreadManagers)
{
Thread thread = new Thread(new ThreadStart(ThreadHandler));
thread.Name = threadManager.Name;
thread.Start();
}
//Called from program > Main() with thread info     
public static void ThreadHandler()
{
Thread thread = Thread.CurrentThread;
var servicesToRun = new ServiceBase[]
{
new MyService(thread.Name),
};
ServiceBase.Run(servicesToRun);
}

标签: c#multithreadingservice

解决方案


推荐阅读