Click here to Skip to main content
15,064,915 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a task to write a console application/Program/Class, In which the application has to run specific method at regular intervals.
My Question is
==>I don't know how to run a application/Program that runs all the time in the back end utilizing only limited resources?
I have tried "Timer" class in c# but the program stops at some pt of time.
Posted
Comments
[no name] 14-Aug-13 5:41am
   
Why don't you just use the task scheduler?
CPallini 14-Aug-13 6:48am
   
5.

C#
private System.Timers.Timer aTimer;

private void StartTimer(double intervalInMilleseconds)
{
    aTimer = new System.Timers.Timer(intervalInMilleseconds);

    aTimer.Elapsed += (sender, args) => someMethod();

    aTimer.Enabled = true;
}

private void someMethod()
{
    aTimer.Enabled = false;

    Console.WriteLine("method called");

    aTimer.Enabled = true;
}
Somewhere, call: StartTimer(#intervalInMilleseconds);

For anything other than "demo" purposes, I think the suggestion here to use WindowsScheduler is the best strategy.

And, have you thought about how you will terminate your application: you better :)
   
Simple way is to create a console application and create the exe file.

And use the Windows scheduler to run that exe file on certain interval.
   
v2
Comments
CPallini 14-Aug-13 6:48am
   
5. The Windows Scheduler is quite effective.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900