c# - 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);
}
解决方案
推荐阅读
- react-native - 如何使指示器覆盖选项卡而不是相反
- excel - 如何在Excel VBA中的同一位置组合来自2个数组的条目
- linux - Bash:在列中查找重复项,根据另一列的比较删除行
- typescript - Nuxt - asyncData 错误:“绑定元素 '$axios' 隐式具有 'any' 类型。”
- visual-studio-code - 如何使用 VS Code 为 Windows 做出本机反应?
- c++ - 首次尝试使用 CMake 编译 Open-CV 时出错
- reactjs - 我使用 fetchAPI 和 useState 收到此错误“TypeError:userData.map 不是函数”
- javascript - JavaScript 检查迭代器是否包含值
- c# - 如何将 html 内容从变量加载到 UWP WebView
- json - 包含管道字符的键的 JQ 提取错误