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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T20:27:43+00:00 2026-05-23T20:27:43+00:00

Can anybody suggest any reasons why a C# timer (created in a code-behind class)

  • 0

Can anybody suggest any reasons why a C# timer (created in a code-behind class) would stop without being told to?

My timer starts on page load and then stops when I click a button. I don’t need to click the button for it to sometimes stop. IIS is not being restarted to my knowledge and no errors are being thrown either.

This is confusing me quite a bit…

Thanks.

    // This gets called on page_load
    private void checkTimer()
    {
        if (!parentTimer.Enabled) // If parent timer is not enabled then it is probably the start of a new day (after a night time server backup which kills timers)
        {
            parentTimer.Interval = 60000; // One minute
            parentTimer.Elapsed += new ElapsedEventHandler(parentTimer_Elapsed); // Define what happens when elapsed
            parentTimer.AutoReset = true; // Set timer to repeat
            parentTimer.Enabled = true; // Start the timer
        }
    }

    protected void btnCancel_Click(object sender, System.EventArgs e)
    {
        parentTimer.Stop();
        ...etc...
    }

Note: I do not change ParentTimer at all in its elapsed method.

Basically ParentTimer governs a list of ChildTimers. If ParentTimer elapses it checks if one or more of the ChildTimers have elapsed too, if so, there is an event, if not then it resets the ChildTimer and carries on.

  • 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-23T20:27:44+00:00Added an answer on May 23, 2026 at 8:27 pm

    A timer is tied to the thread that created it and in the case of ASP.net the thread that handles each page request issued by a given user will change frequently due to the use of worker threads and the thread pool.

    Using a timer at page-level simply won’t work; you need to be tracking the state at Session-level (tied to the particular user) as your starting point.

    In fact, I just wouldn’t use timers at all in a web application, because their execution is simply not guaranteed.

    If you’re using this to run a background task – consider firing up your own worker thread in Application_Start or something like that. The thread will be terminated when the app pool recycles. You should also look at manually shutting the thread down the application is being shut down too.

    Be careful with this, however, this thread can’t assume it’s always the only one running – due to IIS overlapped recycling, when a new one fires up the old one could still be running in the old AppDomain.

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

Sidebar

Related Questions

Can anybody suggest any python * ssl rsa library * , which has a
Can anybody recommend a reliable and decently documented code highlighter for WordPress 2.6.1? I
Can anybody recommend a good code profiler for C++? I came across Shiny -
can anybody show me how to build a string using checkbox. what would be
Can anybody explain the idea behind JSP custom tag libraries and the JSP 2
Can anybody help me out to know the possible reasons for which Apple store
Possible Duplicate: Can anybody suggest the best image resize script in php? I'm still
Can anybody please suggest me some good learning materials on the new Parallel Extensions
Can anyone please suggest me any pointer to an iterative algorithm for insertion and
Can anybody suggest how I can convert an image to a byte array and

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.