【问题标题】:PageAsyncTask - When it times out, do I need to tidy up the long call?PageAsyncTask - 当它超时时,我需要整理长调用吗?
【发布时间】:2015-03-03 16:31:38
【问题描述】:

我正在使用 PageAsyncTask 在 c# (.Net 3.5) 中调用 WCF 服务。

我的问题是,我是否需要在超时时整理代理,或者这是不必要的,因为它是在 Using 块中创建的?

这里有一些伪代码,其中包括一些关于超时的“整理”代码:

private WCFProxy proxy;

IAsyncResult  BeginEvent(...)
{
     Using (proxy = new WCFProxy)
     {
          //do some stuff
          proxy.DoLongRunningWork();

         if (proxy != null) proxy.close();
     }
}

public void TimeoutEvent(IAsyncResult result)
{
       //timeout :-(

       if (proxy != null)
       {
              proxy.Abort();
              proxy = null;
       }    
  }

【问题讨论】:

    标签: c# wcf events asynchronous pageasynctask


    【解决方案1】:

    使用实现IDisposable,它会自动处理它

    但是有更好的做法是说使用“Using”对代理不好!

    请查看此以获取更多信息http://web.archive.org/web/20100703123454/http://old.iserviceoriented.com/blog/post/Indisposable+-+WCF+Gotcha+1.aspx

    【讨论】:

      猜你喜欢
      • 2013-04-15
      • 2020-12-30
      • 1970-01-01
      • 2012-04-15
      • 2018-03-07
      • 1970-01-01
      • 2012-10-30
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多