コード例 #1
0
ファイル: Program.cs プロジェクト: mfmese/AsyncParallelPoc
        public static async void Test()
        {
            var value1         = AsyncServices.GetFirstValueAsync();
            var value2         = AsyncServices.GetSecondValueAsync();
            var throwException = AsyncServices.GetThrowExceptionAsync();

            var tasks = new List <Task <string> >();

            for (int i = 0; i < 10; i++)
            {
                var value3 = AsyncServices.GetSecondValueAsync();
                tasks.Add(value3);
            }

            tasks.Add(value1);
            tasks.Add(value2);
            tasks.Add(throwException);
            Task allTasks = Task.WhenAll(tasks);

            try
            {
                await allTasks;

                tasks.ForEach(task => Console.WriteLine($"Task {0}", task.Result));
            }
            catch (Exception)
            {
                AggregateException allExceptions = allTasks.Exception;
                Console.WriteLine("Exception: " + allExceptions.Message);
            }
        }
コード例 #2
0
ファイル: Program.cs プロジェクト: mfmese/AsyncParallelPoc
        public static void Test()
        {
            var value1          = AsyncServices.GetFirstValueAsync();
            var value2          = AsyncServices.GetSecondValueAsync();
            var throwExceptipon = AsyncServices.GetThrowExceptionAsync();

            var completedTask = Task.WhenAny(value1, value2, throwExceptipon);

            string completedTaskResult = completedTask.Result.Result.ToString();

            Console.WriteLine("completedTask: " + completedTaskResult);
        }
コード例 #3
0
ファイル: Program.cs プロジェクト: mfmese/AsyncParallelPoc
        public static async void Test()
        {
            var value1 = await AsyncServices.GetFirstValueAsync();

            var value2 = await AsyncServices.GetSecondValueAsync();

            var throwException = await AsyncServices.GetThrowExceptionAsync();

            for (int i = 0; i < 10; i++)
            {
                var value3 = await AsyncServices.GetSecondValueAsync();

                Console.WriteLine($"Value3: {0}", value3);
            }

            Console.WriteLine($"Value1: {0}", value1);
            Console.WriteLine($"Value2: {0}", value2);
            Console.WriteLine($"ThrowException: {0}", throwException);
        }
コード例 #4
0
ファイル: Program.cs プロジェクト: mfmese/AsyncParallelPoc
        public static async void Test()
        {
            var value1         = AsyncServices.GetFirstValueAsync();
            var value2         = AsyncServices.GetSecondValueAsync();
            var throwException = AsyncServices.GetThrowExceptionAsync();


            var tasks = new[] { value1, value2, throwException };

            var processingTask = tasks.Select(AwaitAndProcessAsync).ToList();

            var allTasks = Task.WhenAll(processingTask);

            try
            {
                await allTasks;
            }
            catch (Exception)
            {
                AggregateException allExceptions = allTasks.Exception;
                Console.WriteLine("Exception: " + allExceptions.Message);
            }
        }