For Programmers: Free Programming Magazines  


Home > Archive > C# > September 2005 > Timer in C#









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author Timer in C#
Maziar Aflatoun

2005-09-01, 6:58 pm

Hello,

My application allows users to define actions and the time the action should
take place. I store the data in a xml file.Now what is the best way to have
those actions executed at predefined times? Currently I'm usingt the
built-in timer component set to every second? Is that efficient? Is there a
better way of doing this then having to scan the whole XML file every second
(even though it's in the memory) against current time every second?


Thanks
Maz.


FrankVDL@gmail.com

2005-09-01, 6:58 pm

An other way of doing this ....

- Calculate the timespan for the first job in your xml file
- Start a new thread , add a Thread.Sleep with the calculated timespan
to the threaded method.
- Use the FileSystemWatcher component to check if your XML file is
changed externaly, if it is adjust the Thread.Sleep

This way you'r system doesn't have to sync the timer thread evry
second, and it doesn't need to parse the xml every second

Hope this helps
Frank Vanderlinden

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com