示例#1
0
        private static async Task Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            Demo demo = new Demo();

            //await demo.AsParallelDemo();

            //await demo.AsOrderedDemo();

            //await demo.AsSequentialDemo();

            //await demo.WithDegreeOfParallelismDemo();

            //await demo.ForAllDemo();

            AsyncLoopDemo asyncLoopDemo = new AsyncLoopDemo();

            List <string> list = new List <string>()
            {
                "Kishor", "Yogesh", "Eshaan"
            };

            var results = await asyncLoopDemo.LoopAsyncResult(list);

            results
            .ToList()
            .ForEach((item) => Console.WriteLine(item));
        }
        private static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            Task.Run(async() =>
            {
                AsyncDemo asyncDemoObj = new AsyncDemo();

                await asyncDemoObj.DemoOldAsync();

                await asyncDemoObj.DemoNewAsync();

                //string fullName = await asyncDemoObj.DemoOldAsync("Kishor", "Naik");
                //Console.WriteLine(fullName);

                string fullName = await asyncDemoObj.DemoNewWay("Kishor", "Naik");
                Console.WriteLine(fullName);

                fullName = await asyncDemoObj.DemoValueTask("Kishor", "Naik");
                Console.WriteLine(fullName);

                await asyncDemoObj.LongRunningTask();

                await asyncDemoObj.LongRunningParallelism();

                AsyncLoopDemo asyncLoopDemo = new AsyncLoopDemo();

                await asyncLoopDemo.LoopAsync(new List <String>()
                {
                    "Kishor", "Eshaan", "Deepika"
                });

                var result = await asyncLoopDemo.LoopAsyncResult(new List <String>()
                {
                    "Kishor", "Eshaan", "Deepika"
                });
                foreach (var value in result)
                {
                    Console.WriteLine($"Item: {value}");
                }
            }).Wait();
        }