I have this problem: there is a function that makes an http request and returns a data stream. I tested it in a console application - everything works. Now I add it to my wpf application and it freezes - the serverAnswer fetch command is not executed. There are no errors or exceptions. The program seems to be running, but stands still Tell me something.
Function:
public async Task<Stream> GetStream()
{
HttpClient CV18Client = new HttpClient();
var serverAnswer = await CV18Client.GetAsync(adress, HttpCompletionOption.ResponseHeadersRead);
return await serverAnswer.Content.ReadAsStreamAsync();
}
The most probable scenario - your WPF app freezes because UI thread is waiting for the task (web request) to complete, but it completes in another thread. To ensure your task result will be returned in the thread it started you can append
.ConfigureAwait(true);to your async call. So it will be something like that:var myStream = await myApiClient.GetStream().ConfigureAwait(true);