如何在线程中访问相同形式的图片框?跨线程无效-异常 [英] How to access Picture box in Same form in thread ? Cross-threadperation not valid - Exception
本文介绍了如何在线程中访问相同形式的图片框?跨线程无效-异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的代码
Here is my code
private void RefreshButton_Click(object sender, EventArgs e)
{
Thread thread = new Thread(new ThreadStart(VisibleLoadImage));
thread.Start();
RefreshButtonOKClick(); // DO SOMETHING
}
private void VisibleLoadImage()
{
LoadPictureBox.Show();
(or)
''Exception - Cross-threadperation not valid: Control ''groupBoxView'' accessed from a thread other than the thread it was created ''
LoadPictureBox.Visible = true;
}
How to access Picture box in Same form?
推荐答案
问题不是相同的表单,而是不同的线程.您需要告诉我们您正在使用什么框架,但是 ^ ]基本上就是您所需要的.
The issue is not the same form, it''s a different thread. You need to tell us what frameworks you''re using, but this[^] is broadly what you need.
您需要对其进行锁定:
You need to pinvoke it:
private void MakeVisible(PictureBox p, bool vis)
{
if (InvokeRequired)
{
Invoke(new MethodInvoker(delegate { MakeVisible(p, vis); }));
}
else
{
p.Visible = vis;
}
}
这篇关于如何在线程中访问相同形式的图片框?跨线程无效-异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文