Ejemplo n.º 1
0
        static void Main(string[] args)
        {

            


            Action action = async () =>
            {
                // without
                var without = new WithoutAsync();
                without.Completed += (s, e) =>
                {
                    Console.WriteLine("Without Completed");
                    Console.WriteLine(" > {0}", e.Result);
                };
                try
                {
                    without.Start();
                    Console.WriteLine("After without.Start();");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("After without.Start();");
                    Console.WriteLine(" ! {0}", ex.Message);
                }

                // with
                var with = new WithAsync();
                try
                {
                    var result = await with.Start();
                    Console.WriteLine("With completed");
                    Console.WriteLine(" > {0}", result);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("With completed");
                    Console.WriteLine(" ! {0}", ex.Message);
                }
            };

            Console.WriteLine("Begin ALL");
            action.Invoke();
            Console.WriteLine("End ALL");
            Console.Read();
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            Action action = async() =>
            {
                // without
                var without = new WithoutAsync();
                without.Completed += (s, e) =>
                {
                    Console.WriteLine("Without Completed");
                    Console.WriteLine(" > {0}", e.Result);
                };
                try
                {
                    without.Start();
                    Console.WriteLine("After without.Start();");
                }
                catch (Exception ex)
                {
                    Console.WriteLine("After without.Start();");
                    Console.WriteLine(" ! {0}", ex.Message);
                }

                // with
                var with = new WithAsync();
                try
                {
                    var result = await with.Start();

                    Console.WriteLine("With completed");
                    Console.WriteLine(" > {0}", result);
                }
                catch (Exception ex)
                {
                    Console.WriteLine("With completed");
                    Console.WriteLine(" ! {0}", ex.Message);
                }
            };

            Console.WriteLine("Begin ALL");
            action.Invoke();
            Console.WriteLine("End ALL");
            Console.Read();
        }