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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T06:33:04+00:00 2026-05-25T06:33:04+00:00

I wanted to see if anyone had any experience or tips on using timers

  • 0

I wanted to see if anyone had any experience or tips on using timers dynamically. We need a windows service that will periodically check a text file. The text file will hold a market name and a start time. The service then needs to create a timer to perform a countdown and write out countdown information to an xml file… like 23minutes

all of that works now on a windows app for one timer and one countdown…we now want to make this dynamic…

so when the service starts, it would create a timer for each market/countdown time… (exp Phoenix 10am, Chicago 11:45pm, etc).

Then the service would check that text file for any NEW entries… So if the file had Phoenix, Chicago and then had New York added, we would want the service to keep the Phoenix and Chicago timers running and then start a timer for New York.

im just not sure how multiple timers running under a service would interact and how the threading will work when they all need to write to the same xml file.

any thoughts on this?

  • 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-25T06:33:05+00:00Added an answer on May 25, 2026 at 6:33 am

    im just not sure how multiple timers running under a service would interact and how the threading will work when they all need to write to the same xml file.

    any thoughts on this?

    It won’t work well.

    Timers are queued to the thread pool. The thread pool will only create a certain number of active threads at a time:

    http://msdn.microsoft.com/en-us/library/0ka9477y.aspx

    The number of operations that can be queued to the thread pool is limited only by available memory; however, the thread pool limits the number of threads that can be active in the process simultaneously

    In addition, writing to the same file from multiple threads is going to give you bad results.

    Not to mention it will be much harder to figure out what your application is doing if you have all those threads running.

    A simpler approach

    Take an existing timer and build your own timing system upon it that doesn’t use threads.

    • Create a structure defining a countdown entry.

    Code:

    public class Countdown
    {
        public DateTime Time { get; set; }
        public event Action Elapsed { get; set; }
    
        public void RaiseElasped()
        {
            if(Elapsed != null)
                Elapsed();
        }
    }
    
    • Read your file, and create: Dictionary<string, Countdown> (name -> countdown). Put the same code in each action that you were going to put in the timers.

    • Create a FileSystemWatcher to look for changes to your input file. When the file is triggered, modify the dictionary as necessary.

    • Create a single timer with a resolution of one minute.

    • Every time that timer is triggered, check each item in the dictionary. If the target time has passed, call RaiseElapsed. (possibly remove it from the dictionary, too?)

    From this point, it is hard to determine exactly what you’d want to do, because you didn’t describe what gets written to a file, when it happens, how often, or what happens once your countdown has elapsed. You should be able to figure out the rest yourself, though.

    The advantage of this approach is that single-threaded programs are much easier to debug, and you won’t get any of the issues your question asked about (concurrent file access, or having too many threads running).

    The disadvantage is that it might bog down when you have a lot of entries. But if you have a lot of entries, you should really be using a database instead of of files.

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

Sidebar

Related Questions

I came up with a solution, but I wanted to see if anyone had
I just wanted to see if anyone is aware of any other debuggers capable
Has anyone had any luck using a UIPicker in the 3.2 SDK? I'm in
I wanted to see if folks were using decimal for financial applications instead of
I posted on the Carabiner wiki but wanted to see if anyone here was
Windows 8 build 8102, Kinect SDK V1.0 And so it begins that I had
I have a question and wanted to see if anyone else is familiar with
I had a web service written in .NET 2.0 that expose some web methods.
I wanted to see what folks thought were the best way to help junior
I wanted to see what happened if you change the reference of an object

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.