Here is my problem , I am coding a C# application that will log in to a remote SQL server 2008 [Express edition to be precise] and fetch data from the database table (say foo) periodically[after each fetch the SQL client connection is closed ] .
How can I do this process periodically with a time interval like 60 seconds or so (user definable). ??
Instead of
System.Threading.TimerI’d useSystem.Timers.Timerwhich can be configured to be a “one shot” timer using theAutoResetproperty:In that case, as the timer fires only once, you don’t need to worry about locking or synchronization:
It must be noted that this timer as well runs in a separate thread, so the
TimerEventevent will not be called in the context of the thread that created the timer. This is important to know in case you need to update any UI elements.Please note that this does not work for .NET Compact Framework, as it doesn’t know the
System.Timersnamespace – you’ll have to use Richard’s solution in that case.