windows服务程序运行时错误显示“错误1053服务没有及时响应启动或控制请求。”怎么办?
发布网友
发布时间:2022-05-05 10:53
我来回答
共1个回答
热心网友
时间:2023-10-05 14:59
你可能需要在onStart()方法里另起一个线程,在这个线程里可以while(true).
protected override void OnStart(string[] args)
{
// TODO: Add code here to start your service.
if (threadforwork == null)
{
threadforwork = new Thread(workFunction);
}
threadforwork.IsBackground = true;
threadforwork.Start();
}
在onStop()里面将线程杀掉
protected override void OnStop()
{
// TODO: Add code here to perform any tear-down necessary to stop yourservice.
if (threadforwork != null)
{
if (threadforwork.ThreadState == System.Threading.ThreadState.Running)
{
threadforwork.Abort();
}
}
}