이들은 비슷하지만 동일하지 않습니다.
ContinueWith
은 연속을 나타내는 Task
을 반환합니다. 따라서, 귀하의 예를 취할 :
JsonValue json = await response.Content.ReadAsStringAsync()
.ContinueWith<JsonValue>(respTask => JsonValue.Parse(respTask.Result));
단지 표현을 고려 :
response.Content.ReadAsStringAsync()
.ContinueWith<JsonValue>(respTask => JsonValue.Parse(respTask.Result));
이 식의 결과가 ContinueWith
가 예약 계속을 나타내는 Task
이다.
그래서, 때 await
그 표현 :
await response.Content.ReadAsStringAsync()
.ContinueWith<JsonValue>(respTask => JsonValue.Parse(respTask.Result));
당신은 참으로 await
가 Task
이 ContinueWith
에 의해 반환 ING하고 ContinueWith
계속이 완료 될 때까지 json
변수에 할당이 발생하지 않습니다 :
를
JsonValue json = await response.Content.ReadAsStringAsync()
.ContinueWith<JsonValue>(respTask => JsonValue.Parse(respTask.Result));
일반적으로 s 피킹, 나는 ContinueWith
코드를 쓸 때 async
코드를 피한다. 아무것도 과 함께이 아니지만 약간 낮은 수준이며 구문이 더 어색합니다. '이 데이터 액세스 계층의 일부 경우
var responseValue = await response.Content.ReadAsStringAsync();
var json = JsonValue.Parse(responseValue);
가 나는 또한 ConfigureAwait(false)
을 사용하지만 response.Content
에 접근하고 있기 때문에 직접 당신 가정 : 귀하의 경우
, 나는 같은 것을 할 것 나중에이 메서드에서 ASP.NET 컨텍스트가 필요합니다.
async
/await
을 처음 사용 하셨기 때문에 내 async
/await
intro이 도움이 될 수 있습니다.