小编Rex*_*dan的帖子

Task.WaitAll Index Out of Bounds Exception Cause

为什么这不完整?相反,它抛出一个异常,就像没有捕获异常一样.而且,"索引超出数组范围"的例外对我来说没有意义.

        int n = 3;
        string[] names = new string[] { "sally", "fred", "gina" };
        Task[] myTasks = new Task[n];
        for (int y = 0; y < n; y++)
        {
            myTasks[y] = Task.Factory.StartNew(() =>
            {
                Action<string> action = (name) =>
                {
                    try
                    {
                        throw new Exception(name + ", I bet you can't catch me.");
                    }
                    catch (Exception e)
                    {
                        //I caught you... didn't I?
                    }
                };
                action(names[y]);
            });
        }

        Task.WaitAll(myTasks);
        Console.WriteLine("All tasks complete.");//This line is never reached;
Run Code Online (Sandbox Code Playgroud)

c# task aggregateexception

2
推荐指数
1
解决办法
1225
查看次数

标签 统计

aggregateexception ×1

c# ×1

task ×1