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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T23:05:28+00:00 2026-05-21T23:05:28+00:00

I am having troubles with creating a continuous timer. There are multipule staggered threads

  • 0

I am having troubles with creating a continuous timer. There are multipule staggered threads created on timers which will run for some time then come to a complete stop. The maximum threads I am allowing is 5 and the timer interval is set to 10000. So in theory there would be 1 thread executed every 2 seconds.

This happens for a while, but then it stops. currently I am testing in a console app and writing the responses to the app.

I am not exactly sure what is happening here

internal class EngineThreadGenerator
{
    private readonly AutoResetEvent _autoEvent;
    private readonly Action<string, string> _processQueueDelegate;
    private readonly Action<string, string> _purgeQueueDelegate;

    private void createAllowedEmailThreads()
    {
        for (int counter = 0; counter < AppSettings.ProcessQueueAllowedThreads; counter++)
        {
            EmailThread _emailThread = new EmailThread(_collection, _processQueueDelegate, _purgeQueueDelegate);
            TimerCallback _timerCallback = _emailThread.InitEmailThread;
            Timer _stateTimer = new Timer(_timerCallback, _autoEvent, 0, AppSettings.ProcessIntervalInMilliseconds);

            pauseLoop();
        }
    }

Any help here is greatly appreciated! Cheers!

  • 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-21T23:05:29+00:00Added an answer on May 21, 2026 at 11:05 pm

    The reason your timers are dying after 3 minutes is that you have a lot of memory available.

    Which means the garbage collector takes about 3 minutes to get to your objects before collecting them.

    You’re supposed to keep a reference to the timer for the duration of its lifetime. Since you’re not doing that, the timer is eligible for garbage collection as soon as your loop ends.

    3 minutes later, or whenever GC gets around to it, the timer is collected, and your code stops executing.

    So, keep a reference to the timer object, and you should be all set.

    Here’s a simple LINQPad script to test with:

    void Main()
    {
        new Timer(Callback, null, 0, 1000);
        Thread.Sleep(5000);
        Debug.WriteLine("collecting");
        GC.Collect();
        GC.WaitForPendingFinalizers();
        GC.Collect();
        Debug.WriteLine("collected");
        Thread.Sleep(5000);
    }
    
    static void Callback(object state)
    {
        Debug.WriteLine("callback");
    }
    

    Observe that once the main thread runs GC, the callback stops. If, on the other hand, you make a copy of the timer into a field:

    Timer _Timer;
    
    void Main()
    {
        _Timer = new Timer(Callback, null, 0, 1000);
        ...
    

    the timer keeps on ticking past GC.

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

Sidebar

Related Questions

I'm having troubles with creating a simple list (some expandable lists are already working).
I am having some troubles passing a reference to an object which is of
Guys I'm having some troubles subclassing an UIView. I'm creating an IconView. Simply it's
I'm pretty new to the Android scene and I'm having troubles creating an UI
I'm having some troubles with my Rails app after installing (and removing) Compass. bundle
I'm having a-bit of trouble with threads in java. Basically Im creating an array
I'm having some troubles understanding how Guice's singleton instantiations works. I've read the available
I am having trouble creating a SQL select in Oracle, which does the following.
I am having troubles with creating up this sql query to find records having
I'm having troubles with creating NSDictionaries in a loop and adding it to an

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.