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 7431207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T09:15:33+00:00 2026-05-29T09:15:33+00:00

I am trying to do long polling with an HttpWebRequest object. In my C#

  • 0

I am trying to do “long polling” with an HttpWebRequest object.

In my C# app, I am making an HTTP GET request, using HttpWebRequest. And then afterwards, I wait for the response with beginGetResponse(). I am using ThreadPool.RegisterWaitForSingleObject to wait for the response, or to timeout (after 1 minute).

I have set the target web server to take a long time to respond. So that, I have time to disconnect the network cable.

After sending the request, I pull the network cable.

Is there a way to get an exception when this happens? So I don’t have to wait for the timeout?

Instead of an exception, the timeout (from RegisterWaitForSingleObject) happens after the 1 minute timeout has expired.

Is there a way to determine that the network connection went down? Currently, this situation is indistinguishable from the case where the web server takes more than 1 minute to respond.

  • 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-05-29T09:15:34+00:00Added an answer on May 29, 2026 at 9:15 am

    I found a solution:

    Before calling beginGetResponse, I can call the following on the HttpWebRequest:

    req.ServicePoint.SetTcpKeepAlive( true, 10000, 1000)
    

    I think this means that after 10 seconds of inactivity, the client will send a TCP “keep alive” over to the server. That keep alive will fail if the network connection is down because the network cable was pulled.

    So, when the cable is pulled, I a keep alive gets sent within 10 seconds (at most), and then the callback for BeginGetResponse happens. In the callback, I get and exception when I call req.EndGetResponse().

    I guess this defeats one of the benefits of long polling, though. Since we’re still sending packets around.

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

Sidebar

Related Questions

I'm trying to implement a comet style, long polling connection using an XMLHttpResponse object.
I'm trying to implement an http long polling server in Node.js, and have no
I'm trying to create a AJAX push implementation in PHP using a Comet long-polling
I'm trying to serve long polling requests for 60 secs using node.js. The problem
I'm trying to implement long polling using Netty and jQuery. I have it working
I'm trying to get request a json object from the server each 10 seconds
I have been trying for a long time to get SQL Server Express on
I'm trying to implement long polling in a php chat script, however the long
I’m trying to write a custom TCP based long polling server that will serve
I am trying to implement a long polling push-service on my android application (based

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.