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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T01:48:28+00:00 2026-06-14T01:48:28+00:00

I have data which is constantly being read by many threads. This data needs

  • 0

I have data which is constantly being read by many threads. This data needs to be updated daily.

My approach has been to use a ReaderWriterLockSlim to manage access to the data. Every night the first thread to detect the day change applies a WriteLock to the data and updates it.

In order to avoid the constant check for the day change event. I would ideally like to create a System.Timer object as a singleton and have it automatically start and then execute every 24hrs thereafter.

This has been my approach:

First I extended System.Timers to execute the callback on init.

using System.Timers;

namespace Utilities
{
    class AutoStartTimer : Timer
    {
        public AutoStartTimer(ElapsedEventHandler callback, int period):base(period)
        {
            callback(null, null);
            AutoReset = true;
            Elapsed += callback;
            Enabled = true;
        }
    }
}

Then I declared it at a singleton where I needed it.

private static AutoStartTimer _loadDataTimer = 
                                new AutoStartTimer(DataLoader, 86400000); // Daily

This approach is working for me so far. However I would like to know if there are any better ways to implement a Singleton Timer which executes once on initialisation and then for a set period afterwards or if anyone has managed to do this more efficiently without extending the Timer class.

I need to use many of these in my current project so I want to make sure I am using a good approach.

Thanks.

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

    Using a static class:

    public static class DayManager
    {
         public static readonly object SyncRoot = new object();
    
         private static readonly Timer dayTimer;
    
         static DayManager()
         {
             dayTimer = new Timer { AutoReset = true; Enabled = true; Interval = 86400000d };
             dayTimer.Elapsed += OnDayTimerElapsed;
         }
    
         protected void OnDayTimerElapsed(object sender, ElapsedEventArgs e)
         {
             if(DayPassedEvent != null)
             {
                 DayPassedEvent(this, null);
             }
         }
    
         public event EventHandler DayPassedEvent;
    }
    

    Now, in each of the threads you should subscribe to the DayPassedEvent and use Monitor.TryEnter(DayManager.SyncRoot) to acquire a lock on the timer managing class. This means that only one thread should go on to try to update the data and the rest should fail to get the lock and continue with their lives. I’ll leave the exact implementation of this up to you.

    Alternatively, you could remove the SyncRoot from the timer managing class here and use another as you’re already doing, I just provided it for reference only.

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

Sidebar

Related Questions

I have this DB table in which data is constantly being added to. The
I have a 256x256 numpy-array of data which is constantly being changed. on every
I am getting JSON string from website. I have data which looks like this
I have an application (video stream capture) which constantly writes its data to a
Now, I have read these questions which may have a relation with this question:
I have data which resembles the following: D.STEIN,DS,01,ALTRES,TTTTTTFFTT D.STEIN,DS,01,APCASH,TTTTTTFFTT D.STEIN,DS,01,APINH,TTTTTTFFTT D.STEIN,DS,01,APINV,TTTTTTFFTT D.STEIN,DS,01,APMISC,TTTTTTFFTT D.STEIN,DS,01,APPCHK,TTTTTTFFTT D.STEIN,DS,01,APWLNK,TTTTTTFFTT
I have data which resembles the following: D.STEIN,DS,01,ALTRES,TTTTTTFFTT D.STEIN,DS,01,APCASH,TTTTTTFFTT D.STEIN,DS,01,APINH,TTTTTTFFTT D.STEIN,DS,01,APINV,TTTTTTFFTT D.STEIN,DS,01,APMISC,TTTTTTFFTT D.STEIN,DS,01,APPCHK,TTTTTTFFTT D.STEIN,DS,01,APWLNK,TTTTTTFFTT
I have some data which (quite reasonably) uses null and false for different meanings.
I have some data which i need to make some statistics. I need to
I have some data which look like that: PMID- 19587274 OWN - NLM DP

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.