What must be taken into account on executing a batch file as scheduled task?

Using a batch file with just a single command line as scheduled task usually does not make much sense. It would be better to specify directly in scheduled task to run the application executed by the batch file with its parameters which would be in this case %SystemRoot%\System32\wscript.exe with the argument “C:\myfolder\myscript.vbs”. On using just … Read more

How might I schedule a C# Windows Service to perform a task daily?

I wouldn’t use Thread.Sleep(). Either use a scheduled task (as others have mentioned), or set up a timer inside your service, which fires periodically (every 10 minutes for example) and check if the date changed since the last run: private Timer _timer; private DateTime _lastRun = DateTime.Now.AddDays(-1); protected override void OnStart(string[] args) { _timer = … Read more

Creating Scheduled Tasks

You can use Task Scheduler Managed Wrapper: using System; using Microsoft.Win32.TaskScheduler; class Program { static void Main(string[] args) { // Get the service on the local machine using (TaskService ts = new TaskService()) { // Create a new task definition and assign properties TaskDefinition td = ts.NewTask(); td.RegistrationInfo.Description = “Does something”; // Create a trigger … Read more

Scheduling a job with Spring programmatically (with fixedRate set dynamically)

Using a Trigger you can calculate the next execution time on the fly. Something like this should do the trick (adapted from the Javadoc for @EnableScheduling): @Configuration @EnableScheduling public class MyAppConfig implements SchedulingConfigurer { @Autowired Environment env; @Bean public MyBean myBean() { return new MyBean(); } @Bean(destroyMethod = “shutdown”) public Executor taskExecutor() { return Executors.newScheduledThreadPool(100); … Read more