I need to add delay to some code block. I am using Task ContinueWith
to achieve that, it works as expected when tested on my machine but the deployed code is not working.
public void DailyReminder()
{
//Do somethings
System.Threading.Tasks.Task.Delay(300000).ContinueWith(t => EmailAlert()); //This should not block UI
//Do more things, this should not wait for 300000 ms to get excecuted
}
public void EmailAlert()
{
//Send Email
}
For Example i need the below code to produce A B C and D only after the 5 sec delay -
using System;
using System.Threading.Tasks;
namespace HelloWorld
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine("A");
EmailAlert();
Console.WriteLine("C");
}
private static async Task EmailAlert()
{
Console.WriteLine("B");
await Task.Delay(5000);
Console.WriteLine("D");
}
}
}