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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:14:13+00:00 2026-05-26T04:14:13+00:00

I am using MVC 2, I have view which simply displays label with current

  • 0

I am using MVC 2, I have view which simply displays label with current time on it.

I want to update this View(label) every 5 seconds so time will update. I am using below (taken from here) but doesn’t seem to be working.

public ActionResult Time()
    {
        var waitHandle = new AutoResetEvent(false);
        ThreadPool.RegisterWaitForSingleObject(
            waitHandle,
            // Method to execute
            (state, timeout) =>
            {
                // TODO: implement the functionality you want to be executed
                // on every 5 seconds here
                // Important Remark: This method runs on a worker thread drawn 
                // from the thread pool which is also used to service requests
                // so make sure that this method returns as fast as possible or
                // you will be jeopardizing worker threads which could be catastrophic 
                // in a web application. Make sure you don't sleep here and if you were
                // to perform some I/O intensive operation make sure you use asynchronous
                // API and IO completion ports for increased scalability
                ViewData["Time"] = "Current time is: " + DateTime.Now.ToLongTimeString();
            },
            // optional state object to pass to the method
            null,
            // Execute the method after 5 seconds
            TimeSpan.FromSeconds(5),
            // Set this to false to execute it repeatedly every 5 seconds
            false
        );

        return View();
    }

Thanks for help in advance!

  • 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-26T04:14:14+00:00Added an answer on May 26, 2026 at 4:14 am

    What you are doing won’t work as once the initial response is sent to the client, the client will no longer be listening for data from your server for that request. What you want to do is have the client initiate a new request every 5 seconds, then simply return the data for each request. One way to do this is with a refresh header.

    public ActionResult Time()
    {
        this.HttpContext.Response.AddHeader( "refresh", "5; url=" + Url.Action("time") );
    
        return View();
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an application, built using MVC, that produces a view which delivers summary
Using ASP MVC and Entity Framework. In the view, you have a page declaration
I'm using ASP.NET MVC and have a model which has an image (byte array)
I have a simple ASP.Net MVC View which contains an FCKeditor text box (created
We have a large legacy application where we want to start using MVC for
I have a simple form which is using ASP.NET MVC 3 unobtrusive client side
Have you tried using MVC or any other UI pattern for GWT client code.
I'm using MVC 1.0 and have created a RequireSSLAttribute (like the one in ASP.NET
I have a following table using MVC that shows number of items the user
I have an winforms application that was built using MVC. The controller is subscribing

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.