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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T01:33:59+00:00 2026-06-01T01:33:59+00:00

I have a Timer which kicks off and does it’s job indefinitely in it’s

  • 0

I have a Timer which kicks off and does it’s job indefinitely in it’s own thread until something happens in the main thread to disable it, in which case a different one will be enabled. This works perfectly. The only problem is that I want to make COMPLETELY sure the second timer doesn’t run for too long.

Is there a way to make a timer automatically disable after, say, 10 minutes if it doesn’t receive a specific shutdown command due to some malfunction?

I see that the class has a InitializeLifetimeService method. It sounds like it could help but I have no idea how to work it.

Thanks guys and gals 🙂

  • 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-01T01:34:00+00:00Added an answer on June 1, 2026 at 1:34 am

    You might consider starting a third Timer when you start the second one to disable it after a given time.

            Timer t1 = new Timer(1000); // fire every second
            Timer t2 = new Timer(60000); // fire after 10 minutes
            t2.Elapsed += (o, e) => t1.Stop(); // disable timer 1 when timer 2 is elapsed
    
            t1.Start();
            t2.Start();
    

    The example above makes use of System.Timers.Timer by the way. If you are using System.Threading.Timer you might consider a switch there as well for surprisingly enough System.Timers.Timer is the one who is threadsafe by nature, where System.Threading.Timer is not.

    Quite good overview can be found here:
    http://msdn.microsoft.com/en-us/magazine/cc164015.aspx

    EDIT for clarity:
    the line

    t2.Elapsed += (e, o) => t1.Stop();
    

    could also be written as

     t2.Elapsed += new ElapsedEventHandler(t2_Elapsed);
    

    followed by

    void t2_Elapsed(object sender, ElapsedEventArgs e)
    {
        t1.Stop();
    }
    

    which is what you actually get when hitting Ctrl+Space in Visual Studio, given hat you have access to t1 in the lower method.

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

Sidebar

Related Questions

I have a parent which when it starts, kicks off a thread that creates
How can i have timer which runs for every 5 secs continously. below is
I have a static timer class which will be called by ANY webpage to
I have a timer in my JavaScript which needs to emulate clicking a link
I have a Windows Service application which uses a Threading.Timer and a TimerCallback to
I have an application in which I am starting a timer for two task:
Have a question regarding something which has been bugging me for some time now.I'm
We have two applications. Main.exe - which is the main application being updated Update.exe
I have a time_select in which I am trying to set a time value
In my database I have a time stamp column...which reflects a format like this:

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.