C# 跨线程问题,急求 this.pictureBox1.Invoke(_myInvoke); 换成this.pictureBox1.BeginInvoke(_myInvoke); 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 dr = new draws(pictureBox1); for (int i = 0; i < 7; i++) { dr.drawBaseNum(i); } pictureBox1.Image = dr.getBitmap(); 在最后的时候才invoke前面计算的时候在线程中完成this.pictureBox1.Invoke(_myInvoke2); void _myInvoke2(){pictureBox1.Image = dr.getBitmap(); } 你这里犯了一个错误。if (pictureBox1.InvokeRequired) { MyInvoke _myInvoke = new MyInvoke(fun); this.pictureBox1.Invoke(_myInvoke); } 此处又在另外个线程里切回到主线程,你这里的多线程没有存在的任何意义。 把for循环中费时费资源的操作放在多线程或异步中, 最后显示的时候才调用UI操作, 不是这里的问题吧。用picture画图出的问题。(大多数可能) //这样试下public delegate void MyInvoke(draws _draws); private void button1_Click(object sender, EventArgs e) { Thread t = new Thread(new ThreadStart(fun)); t.IsBackground = true; t.Start(); } void fun() { dr = new draws(pictureBox1); for (int i = 0; i < 7; i++) { dr.drawBaseNum(i); } if (pictureBox1.InvokeRequired) { MyInvoke _myInvoke = new MyInvoke(fun); this.pictureBox1.Invoke(_myInvoke,dr); } else { pictureBox1.Image = dr.getBitmap(); } } 用 PICTUREBOX 画图 会出现什么问题?大虾指点一下· 我在 dr.drawBaseNum(i); 里 有对 pictruebox1 复杂的操作会不会是这个问题 要如何解决? dr.drawBaseNum(i); 把这个代码贴出来 UserButton val = null; for (int i = 0; i < arraycontrol.Count; i++) { conData = (ControlData)arraycontrol[i]; val = new UserButton(conData.x, conData.y, conData.EllipseHeigh, conData.EllipseWid, conData.text, conData.color); val.Parent = this.pictureBox1; val.Show(); }这是代码 我自定义了一个控件 我要将它们 全部 创建到 PICTUREBOX1 上 public delegate void MyInvoke(Bitmap bit); private void button_Click(object sender, EventArgs e) { Thread t = new Thread(new ThreadStart(fun)); t.IsBackground = true; t.Start(); } Bitmap DrawBitmap() { dr = new draws(pictureBox1); for (int i = 0; i < 7; i++) { dr.drawBaseNum(i); } return dr.getBitmap(); } void SetPictureImage(Bitmap bit) { pictureBox1.Image = bit; } void fun() { Bitmap bit = DrawBitmap(); if (pictureBox1.InvokeRequired) { MyInvoke _myInvoke = SetPictureImage; this.pictureBox1.Invoke(_myInvoke, new object[] { bit }); } else { SetPictureImage(bit); } } 楼主这样试试 1. pictureBox1.InvokeRequired 换成 this.InvokeRequired;2. this.pictureBox1.Invoke(_myInvoke,dr) 换成 this.invoke(_myinvoke,dr); 参考http://www.cnblogs.com/c2303191/articles/826571.html 我换另外一种方式说一下我在新的线程中用一个新的 PICTUREBOX 对象 进行对其处理这部分 不会假死但是我 一 SHOW() 这个PICTUREBOX 对象 的时候 就会出现假死状态有什么好的方法解决? 新手求教多线程的问题 如何遍历winform中所有的radiobutton控件 求助! client.downloaddata的问题 C#线程基础问题 老问题 上传大文件 请教:在Winform中如何获取所有控件集合! MySQLDriverCS中的MySQLDataAdapter 求助! C#中 BeginAcceptSocket 与BeginAcceptTcpClient 这两个方法有什么不同 问一个C#从excel导入数据到sql2005的问题 C# 实现自动生成拓扑图
for (int i = 0; i < 7; i++)
{
dr.drawBaseNum(i);
}
pictureBox1.Image = dr.getBitmap();
在最后的时候才invoke前面计算的时候在线程中完成this.pictureBox1.Invoke(_myInvoke2); void _myInvoke2(){
pictureBox1.Image = dr.getBitmap();
}
{
MyInvoke _myInvoke = new MyInvoke(fun);
this.pictureBox1.Invoke(_myInvoke);
} 此处又在另外个线程里切回到主线程,你这里的多线程没有存在的任何意义。
//这样试下
public delegate void MyInvoke(draws _draws);
private void button1_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(fun));
t.IsBackground = true;
t.Start();
}
void fun()
{
dr = new draws(pictureBox1);
for (int i = 0; i < 7; i++)
{
dr.drawBaseNum(i);
}
if (pictureBox1.InvokeRequired)
{
MyInvoke _myInvoke = new MyInvoke(fun);
this.pictureBox1.Invoke(_myInvoke,dr);
}
else
{
pictureBox1.Image = dr.getBitmap();
}
}
大虾指点一下·
会不会是这个问题
要如何解决?
把这个代码贴出来
for (int i = 0; i < arraycontrol.Count; i++)
{
conData = (ControlData)arraycontrol[i];
val = new UserButton(conData.x, conData.y, conData.EllipseHeigh, conData.EllipseWid, conData.text, conData.color);
val.Parent = this.pictureBox1;
val.Show();
}这是代码 我自定义了一个控件 我要将它们 全部 创建到 PICTUREBOX1 上
private void button_Click(object sender, EventArgs e)
{
Thread t = new Thread(new ThreadStart(fun));
t.IsBackground = true;
t.Start();
} Bitmap DrawBitmap()
{
dr = new draws(pictureBox1);
for (int i = 0; i < 7; i++)
{
dr.drawBaseNum(i);
}
return dr.getBitmap();
} void SetPictureImage(Bitmap bit)
{
pictureBox1.Image = bit;
} void fun()
{
Bitmap bit = DrawBitmap(); if (pictureBox1.InvokeRequired)
{
MyInvoke _myInvoke = SetPictureImage;
this.pictureBox1.Invoke(_myInvoke, new object[] { bit });
}
else
{
SetPictureImage(bit);
}
}
楼主这样试试
2. this.pictureBox1.Invoke(_myInvoke,dr) 换成 this.invoke(_myinvoke,dr);
我在新的线程中用一个新的 PICTUREBOX 对象 进行对其处理
这部分 不会假死
但是我 一 SHOW() 这个PICTUREBOX 对象 的时候 就会出现假死状态
有什么好的方法解决?