回调继续.下面代码中的
本文关键字:代码 继续 回调 | 更新日期: 2023-09-27 18:05:23
(wcf服务器),如果客户端断开连接,我希望代码继续处理。现在它跳到catch语句并停止处理。回调的目的是最终更新客户端请求的进度,但客户端可以在任何阶段断开连接,如果他想要继续处理。
public void ChatToServer(string texttoServer) // send some text to the server
{
Logging.Write_To_Log_File("Entry", MethodBase.GetCurrentMethod().Name, "", "", "", 1);
try
{
Thread.Sleep(5000);
IMyContractCallBack callback = OperationContext.Current.GetCallbackChannel<IMyContractCallBack>();
callback.callbacktoServer("Progress is 20% complete");
// Some extremely important processing
....
callback.callbacktoServer("Progress is 40% complete");
// Some extremely important processing
....
callback.callbacktoServer("Progress is 60% complete");
// Some extremely important processing
....
callback.callbacktoServer("Progress is 80% complete");
// Some extremely important processing
....
callback.callbacktoServer("Progress is 100% complete");
}
catch (Exception ex)
{
}
}
如果我对您的理解正确,您所需要做的就是捕获回调调用中的通信错误并忽略它们-您可能希望将回调调用放在自己的方法中,以便您不必为每个进度通知站点重复异常处理逻辑。