0

在下面的代码(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)
            {

            }

        }
4

1 回答 1

2

如果我对您的理解正确,您需要做的就是从回调调用中捕获通信错误并忽略它们 - 您可能希望将回调调用放在它自己的方法中,这样您就不必重复异常每个进度通知站点的处理逻辑。

于 2013-03-21T18:36:20.697 回答