C#错误:服务无法启动。服务实例已经在运行

时间:2019-07-15 15:44:02

标签: c# multithreading service

我想知道是否有人可以帮助我解决这个问题,这对使用服务是陌生的,因此非常感谢您的帮助。 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);
}

0 个答案:

没有答案