Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 并行。For循环在完成后不执行代码_C#_For Loop_Parallel Processing_Execution - Fatal编程技术网

C# 并行。For循环在完成后不执行代码

C# 并行。For循环在完成后不执行代码,c#,for-loop,parallel-processing,execution,C#,For Loop,Parallel Processing,Execution,在Parallel.For循环完成后,循环下面的代码将不会执行。即使我设置了一个断点,程序也不会到达它,返回语句也不会被执行。 你知道为什么吗 多谢各位 顺便说一下,c是画布 代码如下: Parallel.For(0, Playfield.Last().Field.GetLength(0), x => { Parallel.For(0, Playfield.Last().Field.GetLength(1), y =>

在Parallel.For循环完成后,循环下面的代码将不会执行。即使我设置了一个断点,程序也不会到达它,返回语句也不会被执行。 你知道为什么吗

多谢各位

顺便说一下,c是画布

代码如下:

        Parallel.For(0, Playfield.Last().Field.GetLength(0), x => 
        {
            Parallel.For(0, Playfield.Last().Field.GetLength(1), y =>
            {
                if (Playfield.Last().Field[x, y] == 1)
                    {
                        c.Children.Add(createRectangle(lengthX, lengthY, x, y));
                    }
            });
        });

        return c;

您可能会在“c.Children.Add”上遇到异常,因为它试图添加交叉线程控件。这在wpf中是不允许的。

您可能会在“c.Children.Add”上遇到异常,因为它试图添加交叉线程控件。这在wpf中是不允许的。

是的,谢谢我出于测试目的禁用了公共语言运行时异常。是的,谢谢我出于测试目的禁用了公共语言运行时异常。