Await Inside Try Finally Statement - CSharp Thread Asynchronous

CSharp examples for Thread Asynchronous:Async

Description

Await Inside Try Finally Statement

Demo Code

using System;//  w  w  w. j a va  2  s  .c om
using System.ComponentModel;
using System.Threading.Tasks;
class AwaitInsideTryFinally
{
   static async Task AwaitInTryFinally(TimeSpan delay)
   {
      Console.WriteLine("Before try block");
      try
      {
         Console.WriteLine("Before await");
         await Task.Delay(delay);
         Console.WriteLine("After await");
      }
      finally
      {
         Console.WriteLine("In finally block");
      }
      Console.WriteLine("After finally block");
   }
   static void Main()
   {
      AwaitInTryFinally(TimeSpan.FromSeconds(1)).Wait();
   }
}

Result


Related Tutorials