httpClient sendAsync 메서드를 테스트하고 있습니다. 동기화가 제대로 작동합니다. 그러나 비동기 http 요청을 수행하려고 할 때 메시지를 처리하기 전에 작업이 종료되었습니다. 이 문제가 발생한 모든 신체?HttpClient SendAsync 스레드 콜백이 응답 구문 분석 전에 죽습니다.
이 동기 호출은
HttpRequestMessage httprequest = new HttpRequestMessage(httpmethod, "http://www.google.ca");
var result = _httpClient.SendAsync(httprequest, HttpCompletionOption.ResponseContentRead, cancellationToken);
HttpResponseMessage response = result.Result;
작동하지만 Asynchrnous 호출이 작동하지 않습니다. 응답을 구문 분석하려고하면 스레드가 종료됩니다.
HttpRequestMessage httprequest = new HttpRequestMessage(httpmethod, "http://www.google.ca");
var result = await _httpClient.SendAsync(httprequest, HttpCompletionOption.ResponseContentRead, cancellationToken);
HttpResponseMessage response = result;
어떤 도움을 주시면 감사하겠습니다.
"스레드가 죽는다"는 것은 무엇을 의미합니까? 예외가 보이거나 응용 프로그램이 종료됩니까? –
출력 창에 다음 메시지가있는 응용 프로그램을 종료했습니다. [3408] vstest.executionengine.appcontainer.x86.exe : 프로그램 추적이 '코드 0 (0x0)'으로 종료되었습니다. 시나리오는 단원 테스트에만 존재합니다. 샘플 앱에서는 정상적으로 작동합니다. – user1331889