Simple Async Method - CSharp Thread Asynchronous

CSharp examples for Thread Asynchronous:Async

Description

Simple Async Method

Demo Code

using System;/*w  w  w .j  a  v a  2 s  .com*/
using System.ComponentModel;
using System.Threading.Tasks;
class SimpleAsyncMethod
{
   static async Task PrintAndWait(TimeSpan delay)
   {
      Console.WriteLine("Before first delay");
      await Task.Delay(delay);
      Console.WriteLine("Between delays");
      await Task.Delay(delay);
      Console.WriteLine("After second delay");
   }
   static void Main()
   {
      PrintAndWait(TimeSpan.FromSeconds(1)).Wait();
   }
}

Result


Related Tutorials