Home > Blockchain >  Promise and Timeout in .net core to wait x seconds
Promise and Timeout in .net core to wait x seconds

Time:10-05

I would like to know if is possible to do this in .net core

Typescript code:

await new Promise((resolve) => setTimeout(resolve, 10000));

I try with but this is not the same.

System.Threading.Thread.Sleep(10000);

Maybe this is better?

await Task.Delay(10000);

CodePudding user response:

The C# equivalent is await Task.Delay(10000);

Task.Delay returns a task (i.e., promise) that completes after the specified time.

  •  Tags:  
  • c#
  • Related