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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T17:30:37+00:00 2026-05-24T17:30:37+00:00

I have an issue with the System.Timers.Timer object. I use the timer object to

  • 0

I have an issue with the System.Timers.Timer object. I use the timer object to perform a task at regular intervals. In the timer constructor I call the method doing the work ( DoTimeCheck() ), to ensure that the task is run once at startup also. The work (at regular intervals) is done in a BackgroundWorker.

I call the timer with this:

 UpdaterTimer ut = UpdaterTimer.UpdaterTimerInstance;

My problem is that I need to delay the first run of the task with 3 minutes(the one that runs at application startup). Subsequent runs (Elapsed event) should run without delay. I thought of doing this by calling

System.Threading.Thread.Sleep(TimeToDelayFirstRunInMiliseconds);

but this fails, because it also hangs the UI of the app (main thread) making it unusable. How can I delay the first run of DoTimeCheck() without hanging the UI?
The code of the timer is below. If the issue is not presented in a clear manner please let me know and I will edit. Thank you in advance.

  public sealed class UpdaterTimer : Timer
{
    private static readonly UpdaterTimer _timer = new UpdaterTimer();
    public static UpdaterTimer UpdaterTimerInstance
    {
        get { return _timer; }
    }

    static UpdaterTimer()
    {
        _timer.AutoReset = true;
        _timer.Interval = Utils.TimeBetweenChecksInMiliseconds;
        _timer.Elapsed += new ElapsedEventHandler(_timer_Elapsed);
        _timer.Start();
        DoTimeCheck();

    }

    static void _timer_Elapsed(object sender, ElapsedEventArgs e)
    {
        DoTimeCheck();
    }

    private static void DoTimeCheck()
    {
        //... work here 
    }
}
  • 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-24T17:30:38+00:00Added an answer on May 24, 2026 at 5:30 pm

    One way of doing this would be to give the Timer Interval an initial value (e.g. 3 minutes). Then, in your Elapsed event handler, you could change the interval to your regular value which will be used from then on.

     _timer.Interval = Utils.InitialCheckInterval;
    
     static void _timer_Elapsed(object sender, ElapsedEventArgs e)
     {
         if (_timer.Interval == Utils.InitialCheckInterval)
         {
             _timer.Interval = Utils.RegularCheckInterval;
         }
    
         DoTimeCheck();
     }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a service that is always running, it has a timer to perform
In my Action, I have an error of type System.MissingMethodException when I use TryUpdateModel.
I have a fairly strange(IMO) issue here with a webservice provided by a third
I have an issue.. I am passing the image as the parameter to my
I have a service that updates some data every minute. When I change the
I have a process that imports a daily file of product registrations, and adds
I have developed an application using Entity Framework , SQL Server 2000, Visual Studio
I've got an application written in groovy. It takes some cmd args and returns
What's the best way of changing some rows back color in DataGridView, when it's
I am developing a website which needs to contain functionality in which the user

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.