저는 비동기 C# 코딩에 익숙하며 Azure 테이블에는 sync + async 호출을 선택할 수 있습니다. 1) 나는 내 메소드에서 엔티티를 가져와야하고 2) 스레드가 그 동안 할 수있는 다른 것을 가지고 있지 않다면, 아래에 비동기 버전의 코드를 사용하는 이유가 무엇입니까? 스레드가 다른 작업을 할 수있게하여 멀티 스레드 응용 프로그램에 처리량을 추가 할 수 있습니까? 동기 호출이 얼마나 "깊숙이"차단되는지는 확실하지 않습니다. 하늘빛 테이블에서 반응을 얻으려면 300ms 이상 걸리는 경우가 있습니다.푸른 색 테이블 API- ExecuteAsync를 사용해야합니까
문맥에서 광자 소켓 서버 구현을 코딩합니다. 스레드 풀과 Fibers를 사용합니다. 나는 그러나이 같은 광자에서 비동기 호출을 사용,이 같은 인터페이스 (더 비동기 이벤트가 없습니다) protected override void OnOperationRequest(OperationRequest o, SendParameters p)
은 내가 할 수있는 구현 오전 : requestFiber.Enqueue(() => DoStuff;);
/* synchronous version of code fragment */
entity = tableRetryPolicy.ExecuteAction(() => {
var result = table.Execute (retrieveOp);
if(result.HttpStatusCode == 404)
return null;
App.CheckHttpStatusCode ("Get (Table) Retrieve", result, 200);
return (T) result.Result;
});
/* async version of code fragment */
var task = tableRetryPolicy.ExecuteAsync(() =>
table.ExecuteAsync (retrieveOp).ContinueWith(t =>
{
if (t.Exception != null)
{
// non-transient exception occurred or retry limit reached
App.log.Error("Get (Table) failed all retries: entityId: " + entityId);
}
else
{
if(t.Result.HttpStatusCode == 404)
return;
App.CheckHttpStatusCode ("Get (Table) Retrieve", t.Result, 200);
entity = (T) t.Result.Result;
}
}
));
task.Wait();
//^dont have anything else we can do with this execution path, except wait!
감사합니다. Joe! 위의 코드 예제에서 task.Wait()은 스레드를 자유롭게 해제하여 table.Execute()가 스레드를 완전히 차단하지만 다른 작업은 수행하도록 할 것입니까? –