4

http://www.asp.net/web-api/overview/web-api-clients/calling-a-web-api-from-a-net-client

I have been using this tutorial to learn how to send and retrieve data from a web API. However is there another way without using Tasks and await? Sometimes my requests are taking a long time to return when others are relatively quick.

Are there any other tutorials that may help? What is the best way to call my web api client to login? I feel I shouldn't be using await and async for this sort of thing but could really use some help.

4
  • You should be using await and async (or some threading model) for any long running method. This prevents the UI from freezing up until the call returns. With that said, this question is not specific enough to give you a good answer. Commented Mar 17, 2014 at 0:51
  • Well my requests are general just to load small amounts of data into a datagridview or similar so they are not long running methods. How would I write an API call to get some data in a similar way to the tutorial but without await and async? Commented Mar 17, 2014 at 0:55
  • @user3427148 More than 30ms is considered long. Most Http requests fall into that category. It's painful at first but you just need to get used to using Async methods. Commented Mar 20, 2014 at 13:49
  • I think this is answer you are looking for. stackoverflow.com/questions/32716174/… Commented Jan 24, 2018 at 7:42

2 Answers 2

4

just download microsoft http api library from nuget manager to your project and use httpClient

Sign up to request clarification or add additional context in comments.

Comments

0

You could just use HttpClient if you like and it is supported even in older versions of .NET, and you would not need to worry about tasks or threading. HttpClient also allows you to get the result async but you would need to provide a callback to be called when the result is ready.

Have a look at http://msdn.microsoft.com/en-us/library/system.net.http.httpclient(v=vs.110).aspx

Having said that, I agree with John comments above that you should use await and async

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.