+ 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?
1 Resposta
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