Webclient's DownloadStringCompleted event handler never called

后端 未结 2 1842
执笔经年
执笔经年 2021-01-22 03:29

I\'m trying to make an asynchronous HTTP GET request using Webclient, however, the registered callback never gets called. I\'ve also tried with the sync one, and it worked fine.

相关标签:
2条回答
  • 2021-01-22 04:22

    Maybe because you disposing the WebClient before it finished downloading. The code execution don't stop on asyncWebRequest.DownloadStringAsync(url); and you are disposing the WebClient object by closing the using statement.

    try to dispose the WebClient on asyncWebRequest_DownloadStringCompleted.

    results

    enter image description here

    0 讨论(0)
  • 2021-01-22 04:26

    The simpliest solution is to add Console.ReadKey() at the end of AsyncWebRequest(url) method. This way asyncWebRequest.DownloadStringAsync(url) will be able to retrieve data.

    0 讨论(0)
提交回复
热议问题