I have a windows service where in I want to create a file every 10 seconds.
I got many reviews that Timer in Windows service would be the best option.
How ca
This should just be a case of firing up a System.Timers.Timer
with the right Interval
(and AutoReset
set to true), and handling Elapsed
(but watch out; the callback is not on any particular thread).
MSDN has an example: http://msdn.microsoft.com/en-us/library/system.timers.timer.elapsed.aspx
also from MSDN:
The Timer component is a server-based timer, which allows you to specify a recurring interval at which the Elapsed event is raised in your application. You can then handle this event to provide regular processing. For example, suppose you have a critical server that must be kept running 24 hours a day, 7 days a week. You could create a service that uses a Timer to periodically check the server and ensure that the system is up and running. If the system is not responding, the service could attempt to restart the server or notify an administrator.
The server-based Timer is designed for use with worker threads in a multithreaded environment. Server timers can move among threads to handle the raised Elapsed event, resulting in more accuracy than Windows timers in raising the event on time.