동기식 메서드의 비동기 래퍼를 만드는 것이 더 좋을까요?비동기 래퍼를 만드는 방법
// sync method
public void LongOperation()
{
//code...
}
// versions of wrapper
public async Task LongOpertionWrapperAsyncV1()
{
var task = Task.Factory.StartNew(LongOperation);
await task.ConfigureAwait(false);
}
public Task LongOpertionWrapperAsyncV2()
{
var task = Task.Factory.StartNew(LongOperation);
task.ConfigureAwait(false);
return task;
}
두 버전의 사용은 다르지 않지만. 값 (작업 <T>)을 반환 방법에 대한
async Task Executor()
{
await LongOpertionWrapperAsyncV1();
await LongOpertionWrapperAsyncV2();
}
, 나는 첫 번째 버전을 사용합니다.
그러나 귀하의 의견을 알고 싶습니다.
그리고 이러한 버전간에 일반적인 차이점이 있습니까?
기록 : http://blogs.msdn.com/b/pfxteam/archive/2012/03/24/10287244.aspx – ken2k
BTW, this :'task.ConfigureAwait (false);'는하지 않습니다. *아무것도*. 'ConfigureAwait()'*는 대기 시간을 반환합니다. 반환 값을 무시하면 아무 효과가 없습니다. – svick