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);}我还有错误