Example #1
0
        public async Task Run()
        {
            var myClass = new MyClass();
            
            //C# 6: It's now possible to use "await" in catch and finally blocks.
            try
            {
                var s = await myClass.GetString();
            }
            catch (Exception)
            {
                await myClass.LogError();
            }
            finally
            {
                await myClass.Close();
            }

            // Previously some annoying workarounds had to be used to get similar behaviour.
            bool failed = true;

            try
            {
                var s = await myClass.GetString();
            }
            catch (Exception)
            {
                failed = true;
            }

            if (failed)
                await myClass.LogError();

            await myClass.Close();
        }
Example #2
0
 static void Main(string[] args)
 {
     var myClass = new MyClass();
     myClass.Run().Wait();
     
     Console.Read();
 }