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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T03:30:41+00:00 2026-06-06T03:30:41+00:00

Im an developing a web application with MVC3, Razor, C# 4, jQuery. Within one

  • 0

Im an developing a web application with MVC3, Razor, C# 4, jQuery.

Within one screen (page) I do AJAX calls to a controller action to get some screen-updates. Using Javascripts setTimeout() I do polling.

To optimize this polling in case where the server does not have screen-updates I like to delay the HTTP response and wait a little until I a) get screen-updates or b) hit some timeout (eg. 10 seconds or so).

I tried to do something like this

[OutputCache(Duration = 0)]
[AcceptVerbs(HttpVerbs.Get)]
public ActionResult CheckForUpdates()
{
    var startTime = DateTime.Now;
    while (_haveUpdates || DateTime.Now > startTime.AddSeconds(10   ))
    {
        Thread.Sleep(3);
    }

    return _haveUpdate ? Json(new {updates = ... }, JsonRequestBehavior.AllowGet) : null;
}

In the view I use Javascript / jQuery like this:

<script>
$(function () {
    scheduleNextCheck();
});

function scheduleNextCheck() {
    setTimeout(function() {
        $.ajax({
            url: "@Url.Action("CheckForUpdates")",
            dataType: 'json',
            data: null,
            timeout: 10000,
            cache: false,
            success: function(data) {
                if (data != null && data.updates != null ) {
                    // Apply Updates
                } else {
                    scheduleNextCheck();
                }
            },
            error: function() {
                scheduleNextCheck();
            }
        });
    }, 2000);
}

When using this code the IIS7 worker process will hang/freeze totally so only killing the worker-process can unlock the entire IIS7 server. So Thread.Sleep() seems not to be a good idea. At least not my applications environment.

Did anybody do timething like this with ASP.Net MVC yet or have any idea?

Thx, Marc

==== Update: ====

Found one of the problems: the while criteria was wrong. It should be like this:

    while (noUdates && DateTime.Now < startTime.AddSeconds(10))

The problem now is that other AJAX-requests are canceled while this sleep-delay-loop is running.

About SignalR: Have to take a closer look but the problem is that this needs additional server- and client-side libraries which I have to get approval for so I was hoping for an “easy” small solution with less impact and less need for training.
But SignalR still is an option for one of the next releases to replace polling-stuff – but need to get some training and experience with this stuff first.

==== Update 2: ====

I am looking for a solutions that works without additional libraries / frameworks so I can apply it to the nearly finished web-application without a huge impact.

  • 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-06T03:30:42+00:00Added an answer on June 6, 2026 at 3:30 am

    You may take a look at SignalR which is designed exactly for such situations. Instead of having the client poll the server with multiple HTTP requests, it is the server that notifies the client when updates are available.

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

Sidebar

Related Questions

I am developing an ASP.Net MVC 3 Web Application using Razor Views. Within the
I am developing a web application in ASP.NET MVC3 with C# and Razor. I
I am developing a web application in ASP.NET MVC3 with C# and Razor. I
I am developing a web application in ASP.NET MVC3 with C# and Razor. The
we are developing a web application using MVC3 and Jquery. we have a situation
I am developing one new area of a fairly large web application using MVC3
I am developing an ASP.Net MVC 3 Web Application. Within some of my Views
we are developing a web application using MVC3 and VS2010. We have some pdf
Iam devloping web application with mvc3.In one my view iam using WebGrid.In webgrid pager
I am developing an ASP.NET MVC 3 web application using Razor and C#. I

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.