I've got some code as well. Here is how to use it:
Declare it in your class
Code:
public partial class Service1 : ServiceBase
{
// Create a threaded timer
private static System.Timers.Timer t = new System.Timers.Timer();
If you are doing a timer, you should use a thread that executes a function which then enables the timer. I'll skip that part though.
In your function:
Code:
// Set the interval in MS for the timer
t.Interval = 30000; // 30 seconds
// TODO: Add code here to start your service.
//Enable the timer and set the interval for 10 seconds
t.Enabled = true;
//Assign a new event handler to the Elapsed method
t.Elapsed += new System.Timers.ElapsedEventHandler(timer1_Tick);
//Start the timer
t.Start();
Your Tick Function:
Code:
private void timer1_Tick(object sender, System.Timers.ElapsedEventArgs e)
{
// Stop the Timer
t.Stop();
t.Enabled = false;
// Execute the function
myFunction();
// Enable the timer
t.Start();
t.Enabled = true;
}
Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum