I have the following code whose purpose is to call a function at a specific time. However I get the exception when WaitTask.Start();
is called Additional information: Start may not be called on a promise-style task.
DateTime today = DateTime.Today;
DateTime twoThirtyET = today.AddHours(14.50);
Execute(CallAtTime, twoThirtyET);
public void Execute(Action action, DateTime ExecutionTime)
{
Task WaitTask = Task.Delay((int)ExecutionTime.Subtract(DateTime.Now).TotalMilliseconds);
WaitTask.ContinueWith(_ => action);
WaitTask.Start();
}
private void CallAtTime()
{
Console.WriteLine("Called at time");
}