【发布时间】:2014-06-07 06:17:00
【问题描述】:
我正在开发一个在 GUI 上包含多线程的项目 这是我的代码 在我的 form.cs 文件中,我使用此代码
delegate void voidstringfunction(System.Drawing.Image x);
public void ShowImage(System.Drawing.Image x)
{
if (pictureBox1.InvokeRequired)
pictureBox1.Invoke(new voidstringfunction(ShowImage), x);
pictureBox1.Image = x;
pictureBox1.Update();
}
public void ThreadFunc(){
SGSserverForm form2 = (SGSserverForm)(Application.OpenForms[0]);
form2.ShowImage(tempImage);
}
//this event is running too
void videoSource_NewFrameEvent(object sender, AForge.Video.NewFrameEventArgs eventArgs)
{
pictureBox5.Invoke(new MethodInvoker(() => pictureBox5.Image = tempIm));
}
当我启动线程时,在 program.cs 文件中我得到这个异常“对象当前正在其他地方使用。” 包含
的行sgsClientForm.ShowDialog();
有什么问题? 谢谢大家
【问题讨论】:
-
把try catch放到你使用过的线程和函数中,尝试定位问题的确切位置。由于您没有提供足够的信息,因此很难找出问题所在。
标签: c# multithreading user-interface