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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:18:34+00:00 2026-05-27T23:18:34+00:00

I have a once Timer that calls a function every 15 seconds, it works

  • 0

I have a once Timer that calls a function every 15 seconds, it works for the first 5 times, but then does not elapse for the 6th, even though it is created, any ideas?

The processing time could take longer than 15 seconds, if so Thread A could be processing data while Thread B sends out a new request for data. Thread B cannot start until the processing of Thread A has finished.

const int DATAREFRESH = 15000;

void RequestUpdate()
{
    // Some data processing goes here
    Console.WriteLine("Update");

    // Set the timer
    Timer t = new Timer(new TimerCallback(TimeOutCallback), null, DATAREFRESH, Timeout.Infinite);
}

private void TimeOutCallback(object state)
{
    RequestUpdate();
}

In the Output window, “Update” is displayed 5 times, then after then, nothing. It hasnt frozen, I see that ~8 threads terminate after the last “Update”.

How can I get this to work infinitely?

  • 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-27T23:18:34+00:00Added an answer on May 27, 2026 at 11:18 pm

    It seems very weird to instantiate a new timer from within the callback. A more realistic example would be one in which you are performing the work inside the timer callback. Also you seem to be incorrectly calling the Timer constructor. If you want the callback to execute at regular intervals (15 seconds in your case) you could use the following:

    const int DATAREFRESH = 15000;
    private Timer _timer;
    
    void RequestUpdate()
    {
        // Set the timer
        _timer = new Timer(TimeOutCallback, null, 0, DATAREFRESH);
    }
    
    private void TimeOutCallback(object state)
    {
        // Some data processing goes here
        Console.WriteLine("Update");
    }
    

    Also notice how I have inverted the arguments passed to the timer so that it executes the callback every 15 seconds.

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

Sidebar

Related Questions

Once every several times the calls to the Facebook API are not finished (or
I have one costly function that gets called many times and there is a
I have a array.each function that calls a JSONP request for each item and
I have a windowless timer (no WM_TIMER) which fires a callback function only once
I have once again fleshed out Ruby, after two years of not touching it,
Once you have your first set of requirements and design done where do you
I have a program that depends on an external shared library, but after a
Specifically, I have a DB class that opens and closes multiple MySQL connections every
I have a script that I run which does a lot of tasks and
I have an ASP.Net application that calls an Amazon Web Service to start a

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.