Silverlight 3에서 wcf 서비스를 호출하고 별도의 스레드에서 UI를 업데이트하는 시나리오에서 이벤트 순서에 관한 질문이 있습니다. 기본적으로, 나는 내가하고있는 일이 정확한지를 알고 싶다. 샘플은 다음과 같다. 이것은 실제 코드를 게시하는 방법을 잘 모르므로 여기에 내 첫 번째 게시물입니다. 샘플은 다음과 같습니다 :Silverlight 3에서 비동기 웹 서비스 호출
//<summary>
public static void Load(string userId)
{
//Build the request.
GetUserNameRequest request =
new GetUserNameRequest { UserId = userId };
//Open the connection.
instance.serviceClient = ServiceController.UserService;
//Make the request.
instance.serviceClient.GetUserNameCompleted
+= UserService_GetUserNameCompleted;
instance.serviceClient.GetGetUserNameAsync(request);
return instance.VM;
}
/// <summary>
private static void UserService_GetUserNameCompleted(object sender, GetUserNameCompletedEventArgs e)
{
try
{
Controller.UIDispatcher.BeginInvoke(() =>
{
//Load the response.
if (e.Result != null && e.Result.Success)
{
LoadResponse(e.Result);
}
//Completed loading data.
});
}
finally
{
instance.serviceClient.GetUserNameCompleted
-= UserService_GetUserNameCompleted;
ServiceHelper.CloseService(instance.serviceClient);
}
}
그래서 내 질문에 그 예외가 발생하면 내가는 "마지막으로"블록 캐치 그 응답을합니다로드하고 때 기본적으로 내 UI 스레드의 내부에있다? 그렇지 않다면 나는 응답을로드 할 람다 안에 다른 try/catch를 넣어야합니까?
또한 ui 스레드에서로드를 실행하고 있기 때문에 UI 스레드가 업데이트되기 전에 finally가 실행될 수 있습니까? 결과적으로로드가 완료되기 전에 Servicehelper.CloseService()를 호출 할 수 있습니까?
나는이 방법을 사용하여 간헐적 인 문제가 있기 때문에 물어 본다.