C# WPF async/await HTTP request | Sololearn: Learn to code for FREE!

+1

C# WPF async/await HTTP request

So I'm writing small program which is to help me in game. And every once in a while (every 1 minute) it has to do asynchronous http request to download my equipment from server. I tried to do it with async/await, BackgroudWorker etc. Every try ended up in failure (main thread freeze), because in the end task have to be executed in synchronous method. Is there any design pattern or "good practice" to create background http requests?

12/31/2018 3:07:00 AM

Jakub Stasiak

1 Answer

New Answer

0

Assign the callback using BeginGetReponse() and EndGetResponse() methods HttpWebRequest webRequest; void StartWebRequest() { webRequest.BeginGetResponse(new AsyncCallback(FinishWebRequest), null); } void FinishWebRequest(IAsyncResult result) { webRequest.EndGetResponse(result); } Reference: https://stackoverflow.com/questions/202481/how-to-use-httpwebrequest-net-asynchronously