Question Asynchronous APIs and Background Threads

danfloun

Member
Joined
Apr 5, 2010
Messages
23
Programming Experience
Beginner
Hi,

When I run WebRequest or HttpWebRequest to check for a response from my server, all works fine.

To initiate the default timeout built into WebRequest, I disabled the internet connection in my router. During the attempt for a request the UI freezes, which I know is normal.

So, I'm puzzled as to whether I use an Asynchronous HttpWebRequest, or simply initiate the WebRequest in a background thread.

My understanding is that it is basically the same thing, is this wrong!

My requirements;

When I click a button, it does various procedures to check for an internet connection. Upon getting a result it displays this in a textbox on the UI.
So if I run a WebRequest in the background, I don't want the UI to freeze and I want a callback from the background thread or Async API to update the textbox with the results.

My question;
What is the difference between using an Asynchronous HttpWebRequest and running a WebRequest in a background thread?

Which should I use?


Thanks
Danny
 
If an asynchronous method is available, I'd use that over creating my own thread. Asynchronous methods generally execute on ThreadPool threads, so they are managed by the system and generally provide better overall performance.
 
If an asynchronous method is available, I'd use that over creating my own thread. Asynchronous methods generally execute on ThreadPool threads, so they are managed by the system and generally provide better overall performance.

Great thanks, I'll go with Async then.
By the way, do you ever leave this forums, perhaps you are a form of AI that patrols these boards feeding on questions ;)

Thanks, I appreciate your help.

Danny
 
Back
Top