Async Method With Simple Loop - CSharp Thread Asynchronous

CSharp examples for Thread Asynchronous:Async

Description

Async Method With Simple Loop

Demo Code

using System;//  w ww. j av  a 2 s . c om
using System.ComponentModel;
using System.Threading.Tasks;
class MainClass
{
   static async Task PrintAndWaitWithSimpleLoop(TimeSpan delay)
   {
      Console.WriteLine("Before first delay");
      await Task.Delay(delay);
      for (int i = 0; i < 3; i++)
      {
         Console.WriteLine("Between delays");
      }
      await Task.Delay(delay);
      Console.WriteLine("After second delay");
   }
   static void Main()
   {
      PrintAndWaitWithSimpleLoop(TimeSpan.FromSeconds(1)).Wait();
   }
}

Result


Related Tutorials