I'm making a C# program in my Visual Studio and I have button that on "Click" is suppose to make request to .php file in Internet and to read json, rest or soap (not sure which is the most confortable for C#). I'm using new WebClient().DownloadString(url);
My questions are
- why the first time I click the button (use the function) the whole program freeze and after that It's not freezing ?
- how to prevent the "freezing effect" ?
- is there a better way to retrieve that information from the web ?
- json, rest or soap is preferable?
You're connecting to an external resource, this will take time, and you're consuming content from this resource which also takes time. DownloadString
is a blocking task your main application will wait until it has returned something.
Use async methods that WebClient provides. DownloadStringTaskAsync
.
Documentation can be found here: https://msdn.microsoft.com/en-us/library/hh194294%28v=vs.110%29.aspx
Previous asked question: Webclient calls to DownloadString cause my app to freeze
That's all I have for you.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.