0

I'm using PageAsyncTask to call a WCF service in c# (.Net 3.5).

My question is, do I need to tidy up the proxy on time-out, or is this unnecessary because it is created in a Using block?

Here's some pseudo code which includes some "tidy-up" code on time-out:

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;
       }    
  }
MatthewMartin
  • 32,326
  • 33
  • 105
  • 164
DomBat
  • 1,981
  • 5
  • 27
  • 42

1 Answers1

1

Using implements IDisposable and it automatically disposes it.

But there is better practice which says that using "Using" goes bad with proxies!

Please, check this out for more info: http://web.archive.org/web/20100703123454/http://old.iserviceoriented.com/blog/post/Indisposable+-+WCF+Gotcha+1.aspx

TheCodeLord
  • 417
  • 6
  • 12