언제

2009-06-17 5 views
5

가정하면 내가 동기 버전으로 시작 비동기 패턴으로 WCF 개체를 처리하는 ?언제

2)는()을 사용하여 사용할 수 있습니까?

답변

5

: http://caught-in-a-web.blogspot.com/2008/05/best-practices-how-to-dispose-wcf.html

모범 사례 : WCF 클라이언트에게 (Visual Basic의 경우 사용)을 사용하여 문

사용을 폐기 방법 폐기 WCF 클라이언트를 사용하지 않는 것이 좋습니다. 왜냐하면 using 문이 끝나면 예외가 발생하여 다른 예외를 숨길 수 있기 때문입니다.


using (CalculatorClient client = new CalculatorClient()) 
{ 
... 
} // this line might throw 

Console.WriteLine("Hope this code wasn't important, because it might not happen."); 

The correct way to do it is: 
try 
{ 
    client.Close(); 
} 
catch (CommunicationException) 
{ 
    client.Abort(); 
} 
catch (TimeoutException) 
{ 
    client.Abort(); 
} 
catch 
{ 
    client.Abort(); 
    throw; 
} 
+0

@ 존 잔 블레어, 답변을 검토해 주셔서 감사합니다. –

0

서비스가 관리되지 않는 리소스에 액세스하지 않으므로 범위를 벗어나서 GC가 처리하도록하십시오. 로템 블룸의 블로그에서

관련 문제