Meeting the needs of your business from a distance

Timers in .NET

by Mark Shiffer 12/6/2007 10:16:00 AM

I am currently tasked with creating a Job Scheduler windows service and have been doing some threading research. I have come to the conclusion that I will be using a Timer to trigger when the next job is to get fired off. (there are plenty of issues in addition to be dealt with here that I will not mention: cache updating, synchronization issues, etc...). .NET has 3 native timer classes as described below. After reading some information from others who have tried unsucessfully to implement Systm.Timers.Timer in a windows service, I have decided to go with the System.Threading.Timer. I will already be dealing with plenty of threading and synchronization issues, so I would like to limit the possibility of chasing down other problems. The System.Threading.Timer is lighter weight than the System.Timers.Timer, however, the System.Timers.Timer has some nice features, such as, the adding/removing of listeners after the timer has been instantiated. I can see why others decided to try to use it in their services.  

Feature description System.Timers.Timer System.Threading.Timer System.Windows.Forms.Timer
Support for adding and removing listeners after the timer is instantiated. Yes No Yes
Supports call backs on the user-interface thread Yes No Yes
Calls back from threads obtained from the thread pool Yes Yes No
Supports drag-and-drop in the Windows Forms Designer Yes No Yes
Suitable for running in a server multi-threaded environment Yes Yes No
Includes support for passing arbitrary state from the timer initialization to the callback. No Yes No
Implements IDisposable Yes Yes Yes
Supports one-off callbacks as well as periodic repeating callbacks Yes Yes Yes
Accessible across application domain boundaries Yes Yes Yes
Supports IComponent – hostable in an IContainer Yes No Yes

Be the first to rate this post

  • Currently 0/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Tags: , ,

Research | Issues

Related posts

Add comment


(Will show your Gravatar icon)  

  Country flag





Live preview

July 9. 2008 00:22

About the author

Name of author Mark Shiffer
CEO & CIO of MS Consulting

E-mail me Send mail

Calendar

<<  July 2008  >>
MoTuWeThFrSaSu
30123456
78910111213
14151617181920
21222324252627
28293031123
45678910

View posts in large calendar

Pages

    Recent posts

    Recent comments

    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2008

    Sign in

    Copyright © 2001-2008 MS Consulting, Inc. All Rights Reserved.