Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scheduling Task for future execution

I have looked at the Task and Timer class API's, but could not find information on how to schedule a Task for future execution. Using the Timer class, I can schedule threads for future execution, but I need to schedule Tasks. Task has .Delay(...) methods, but not sure delay is similar to scheduling.

Edit(clarification): I want to start tasks after x minutes.

like image 230
newprint Avatar asked Oct 30 '14 14:10

newprint


People also ask

Which command is use for scheduling future tasks?

You can use the at command to schedule future tasks in a Linux system. Similar to the crontab file that works with the cron daemon, the at command works in conjunction with the atd daemon.

What do you mean by scheduling tasks?

In computing, scheduling is the action of assigning resources to perform tasks. The resources may be processors, network links or expansion cards. The tasks may be threads, processes or data flows. The scheduling activity is carried out by a process called scheduler.

How do I schedule a task to run?

Go to the Scheduled Tasks applet in Control Panel, right-click the task you want to start immediately, and select Run from the displayed context menu.

What is an example of scheduling?

To schedule is to set up a specific time when something will occur. An example of schedule is when you make a doctor's appointment. Schedule is a plan for when things will occur or events will take place. An example of schedule is the times when your courses start and end.


1 Answers

You should use Task.Delay (which internally is implemented using a System.Threading.Timer):

async Task Foo()
{
    await Task.Delay(TimeSpan.FromMinutes(30));
    // Do something
}

While the delay is "executed" there is no thread being used. When the wait ends the work after it would be scheduled for execution.

like image 105
i3arnon Avatar answered Oct 05 '22 02:10

i3arnon