I need an application running in the background in the system tray, 3 times a day, at 08:00, 12:00 and 16:00 it runs an .exe file.
I need an application running in the background in the system tray, 3 times a day, at 08:00, 12:00 and 16:00 it runs an .exe file.
You can use the Quartz Enterprise Scheduler .NET library to run scheduled tasks in an application, either at a pre- defined or from time to time.
Quartz.NET is a full-featured, open source job scheduling system that can be used from smallest apps to large scale enterprise systems.
I like to use the FluentScheduler , as its name suggests, it has fluent writing.
With it you can write something like this:
using FluentScheduler;
public class MeuAgendamento : Registry
{
public MeuAgendamento()
{
Schedule(() => Console.WriteLine("Vou executar todos os dias às 08:00 ")).ToRunEvery(1).Days().At(8, 0);
Schedule(() => Console.WriteLine("Vou executar todos os dias às 12:00 ")).ToRunEvery(1).Days().At(12, 0);
Schedule(() => Console.WriteLine("Vou executar todos os dias às 16:00 ")).ToRunEvery(1).Days().At(16, 0);
Schedule(() => Console.WriteLine("E se quiser posso executar a cada 3 meses, na primeira sexta-feira às 11:47 ")).ToRunEvery(3).Months().OnTheFirst(DayOfWeek.Friday).At(11, 47);
Schedule(() => MeuMetodo()).ToRunNow().AndEvery(4).Hours();
}
private void MeuMetodo()
{
Console.WriteLine("Ou executar um método agora e então cada 4 horas");
}
}
//Depois basta inicializar os agendamentos.
//Se for um serviço do windows essa inicialização pode ser no OnStart do serviço.
//Se for um webSite, essa inicialização pode ocorrer no Application_Start.
class static Main (string[] args)
{
TaskManager.Initialize(new MeuAgendamento());
}
You can download it from Nuget.