Windows 服务没有停止,卡在取消订阅 ews 订阅

Windows Service not stopping, stuck at unsubscribing ews subscription

该服务就像邮箱上的邮件监视器,在新服务器上安装后运行良好。但是,在停止它时,我收到此错误消息

the service cannot accept control messages at this time

所有杀死它的方法都没有用。 根据日志,它卡在 removeSubscription()

public static void Unsubscribe ()
{
     if (_ss.Id.Length>0){
              Logger.log("Reached Here");
             _connection.RemoveSubscription(_ss);
       }
}

这里_ss是streamingSubscription,_connection是streamingSubscriptionConnection引用

你能告诉我如何解决吗? P.S.: 相同的服务在其他服务器上运行良好。

这样就可以杀了它

先获取PID sc queryex <servicename>

然后使用 taskkill 杀死 pid taskkill /pid <pid> /f

在管理员命令提示符中

嗯,实际上这个函数在以前的服务器上运行得很好,所以没有使用 try catch 块来处理异常。

当我记录异常时,发现它抛出了一个错误,需要先关闭连接。所以将代码更改为

_connection.close();
_connection.RemoveSubscription();

这解决了问题。