Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8422855
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:34:21+00:00 2026-06-10T03:34:21+00:00

I have a class library that I’m porting to a Windows 8 Store Class

  • 0

I have a class library that I’m porting to a Windows 8 Store Class Library.
One of the methods uses the now not supported synchronous HttpWebRequest.
I need to keep the method synchronous as the Async work has been done in the applications not the library and changing it would take a great deal of effort.
I’ve changed it to a Synchronous task with IAsyncresult but I’m not sure how to set the request timeout using this code. Can someone help?
Also can anyone see any other issues I may encounter with this code?

//Create Web Request
HttpWebRequest request = WebRequest.Create(uri) as HttpWebRequest;
IAsyncResult asyncResult = request.BeginGetResponse(null, null);

if (asyncResult.AsyncWaitHandle.WaitOne(5 * 1000))
{
    //Get Response
    using (HttpWebResponse response = request.EndGetResponse(asyncResult) as HttpWebResponse)
    {
        if (request.HaveResponse && response != null)
        {
            using (Stream reader = response.GetResponseStream())
            {
                result = XDocument.Load(reader);
            }
        }
    }
}
else
{
    request.Abort();
}

UPDATE: I’ve added a waithandle to the request and if it times out I abort the httpwebrequest. Does this take care of any threads started by HttpWebRequest?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T03:34:22+00:00Added an answer on June 10, 2026 at 3:34 am

    How about:

    if(false == request.GetResponseAsync().Wait(DateTime.Now.AddMinutes(2.0)))
    {
        Trace.WriteLine("timeout");
        return;
    }
    //...
    

    Now keep in mind, this is simply the timeout to wait on the asynchronous operation. To specifically deal with a timeout on the response/requeststream operation, see HttpWebRequest.Timeout.

    You don’t have to use async/await with *Async methods. They simply return a Task<T> object that you can work with and use methods like Wait, ContinueWith, etc… Much easier than dealing with the Begin/End (APM pattern)…

    FWIW the *Async pattern is called the Task Asynchronous Pattern (TAP). It seems to be the recommended pattern now, replacing the Asynchronous Programming Model (APM, Begin/End) and Event-based Asynchronous Pattern (EPM, Completed, CancelAsync, etc…).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a C# class library that contains methods that need to be used
I have a c# class library project that uses a COM dll registered on
I have a class library file that is not is not getting picked up
I have a class library that targets .NET 3.5. Now, I would like to
I have a class library that uses some xml files found in its own
I have a class library that interacts with a WCF service, and uses an
I'm building a class library that will have some public & private methods. I
We wrote a small Windows class library that implements extension methods for some standard
I have a class library that has settings within an app.config. I know that
My Scenario I have a class library that is going to be called from

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.