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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T14:39:04+00:00 2026-05-15T14:39:04+00:00

I want to trigger KillZombies every night at midnight. The problem I’m having is

  • 0

I want to trigger KillZombies every night at midnight.
The problem I’m having is that the first timer interval is retained and not reset to 86400000 milliseconds as I’m trying to do in my method.

Is there any way to remove the old interval and replace it with a new one?

System.Timers.Timer Timer = new System.Timers.Timer();
Timer.Elapsed += new ElapsedEventHandler(KillZombies);
Timer.Interval = MillisecondsToMidnight;
Timer.Start()

private void KillZombies(object source, ElapsedEventArgs e)
{
//Kill zombies
Timer.Interval = 86400000; //Milliseconds per 24 hours
}
  • 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-15T14:39:05+00:00Added an answer on May 15, 2026 at 2:39 pm

    FWIW, when using Timers, I always set the AutoReset property to false. This prevents the timer from starting up again, so you have to call Timer.Start() to get it to start counting again. This would avoid the extra calls to Stop()

    Also, to be explicit, I would have a function that calculates milliseconds to midnight each time and assign that to the timer’s interval every time. Would make your code more clear. And also, if you use Timer.AutoRest = false, the timer won’t start counting until you call Timer.Start(), which means if you put the Start() call at the end of your KillZombies method and that method takes 5 seconds to execute, your timer should then be 86400000 - 5000. That 5 second shift would add up over time.

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

Sidebar

Related Questions

I want to trigger an event that causes the ScrollPane to start scrolling up
I want a trigger to fire only when UPDATEs are user-initiated (not me running
I want to trigger a form submit, but not have my usual handlers for
Every time that I want to do a Layout, I'm getting a black layout
Possible Duplicate: OpenGL or DirectX? Not want to trigger war, but really want to
I want to trigger a hyperlink by hitting Enter using jQuery. I have the
Short version: I want to trigger the Form_Load() event without making the form visible.
So I want to trigger an event (pausing/unpausing some media) whenever the user presses
I often want to trigger a certain function just once, but I need to
I want to create a trigger to check what is being deleted against business

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.