Using a timer to run an executable file at a specific time
Lee, Cheul Woo
Usually, you use the Windows Task Scheduler to run an executable file at a specific time or when a specific event occurs. This article introduces a code that uses a timer in a program to run an executable file at a specific time.
The static function below is called when a timer event occurs. The parameter settingTime is a specific time, the parameter now is the current time, the parameter period is the timer cycle, and the parameter processPath is an executable file.
private static void CheckTime(TimeOnly settingTime, TimeOnly now, TimeSpan period, string processPath)
{
if (now < settingTime)
{
var diff = settingTime - now;
if (diff > period)
{
}
else
{
// To-Do.
System.Diagnostics.Process.Start(processPath!);
}
}
}
The To-Do section of the code above makes a specific executable file run. You can put the tasks you want to do in this section.