Search code examples
asynchronouscallbackwebclientuwpwebresponse

WebResponse reading with callbacks


I have an app where the user can choose to download all content and this was done with this method on other platforms

 resp.GetResponseStream().BeginRead(mBuffer, 0, 1448, new AsyncCallback(EndRead), resp);

but a BeginRead-method is not present in the .NET framework used by UWP applications. I need a way to do this in the same way as the other platforms do it, so I can use the callback-function for progressbar updating.

Any ideas?


Solution

  • I need a way to do this in the same way as the other platforms do it, so I can use the callback-function for progressbar updating.

    You can use this way as a workaround:

            var request = WebRequest.CreateHttp("http://www.bing.com");
    
            var response = await request.GetResponseAsync();
    
            byte[] buffer = new byte[1024];
    
            var stream = await response.GetResponseStream().ReadAsync(buffer, 0, 1024);
    
            // add callback actions here