Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/265.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# 旋转picturebox时,对象当前正在其他位置使用_C#_Exception_Rotation_Picturebox_Unhandled - Fatal编程技术网

C# 旋转picturebox时,对象当前正在其他位置使用

C# 旋转picturebox时,对象当前正在其他位置使用,c#,exception,rotation,picturebox,unhandled,C#,Exception,Rotation,Picturebox,Unhandled,我有三张图片,每一张都在一个图片盒中,当线程开始旋转时 threads[0] = new Thread(new ThreadStart(Display1)); place(ref threads[0], comboBox1.SelectedIndex); threads[0].Start(); protected void Display1() { for (long i = 0L; i < 200000; i++)

我有三张图片,每一张都在一个图片盒中,当线程开始旋转时

threads[0] = new Thread(new ThreadStart(Display1));
        place(ref threads[0], comboBox1.SelectedIndex);
        threads[0].Start();
   protected void Display1()
    {
        for (long i = 0L; i < 200000; i++)
        {


            {
                Image img = pictureBox1.Image;
                img.RotateFlip(RotateFlipType.Rotate90FlipNone);
                pictureBox1.Refresh();
            }
        }

    }
然后在display1函数中,我使用下面的代码进行旋转

threads[0] = new Thread(new ThreadStart(Display1));
        place(ref threads[0], comboBox1.SelectedIndex);
        threads[0].Start();
   protected void Display1()
    {
        for (long i = 0L; i < 200000; i++)
        {


            {
                Image img = pictureBox1.Image;
                img.RotateFlip(RotateFlipType.Rotate90FlipNone);
                pictureBox1.Refresh();
            }
        }

    }
protectedvoid Display1()
{
用于(长i=0L;i<200000;i++)
{
{
图像img=pictureBox1.图像;
img.RotateFlip(RotateFlipType.Rotate90FlipNone);
pictureBox1.Refresh();
}
}
}

但它只是得到未处理的异常“对象当前在其他地方使用”我尝试使用lock和picturebox1.invalidate,但我没有用。

你不能从非UI线程随机更新UI控件。我定义了一个旋转类,该类有一个函数获取图像并旋转它,然后返回它,我还添加了以下代码:for(inti=0;i<8;i++){Image-img;this.Invoke((MethodInvoker)委托{img=pictureBox2.Image;});this.Invoke((MethodInvoker)委托{pictureBox2.Image=Rotating.Rotate(img);}我还有错误