关于Thread中显示图片的一个小问题

yumanqing 2012-09-13 04:30:03

private void button3_Click(object sender, EventArgs e)
{
//try
//{
pictureBox1.Visible = true; //这里显示不出来
button3.Enabled = false;
System.Threading.Thread.Sleep(200);

System.Threading.Thread th = new System.Threading.Thread(ttt);
th.Start();





//pictureBox1.Visible = false;
button3.Enabled = true;
button3.Text = x.ToString();
pictureBox1.Visible = false;
//}
//catch()
//{}
//finally
//{}
}

private void ttt()
{
string str = "";
for (double i = 0; i < 999999999999; i++)
{
x += i;
str += i.ToString();
}

}


主要想实现的目的是在线程中加载数据,把图片显示出来给用户提示下,可是图片就是显示不出来
...全文
160 11 打赏 收藏 转发到动态 举报
写回复
用AI写文章
11 条回复
切换为时间正序
请发表友善的回复…
发表回复
嘶吼的蚂蚁 2012-09-14
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]

你的代码主线程一直执行下去,也就说 pictureBox1.Visible = true; // ,启动了次线程,次线程还没结束,接着就执行了 pictureBox1.Visible = false; 图片当然是一闪而过。
这样做:
private void ttt()
{
button3.Enabled = false;
……
[/Quote]
我不对你的观点做任何评价,也请你别对我的代码做任何评价。谢谢!~
yumanqing 2012-09-14
  • 打赏
  • 举报
回复
问题搞定,什么东西还有自己多琢磨啊
yumanqing 2012-09-14
  • 打赏
  • 举报
回复
问题搞定,看来什么东西还要靠自己慢慢琢磨啊,CSDN上的人气也不行了。。。
zhleiyang 2012-09-13
  • 打赏
  • 举报
回复
你的代码主线程一直执行下去,也就说 pictureBox1.Visible = true; // ,启动了次线程,次线程还没结束,接着就执行了 pictureBox1.Visible = false; 图片当然是一闪而过。
这样做:
private void ttt()
{
button3.Enabled = false;
string str = "";
for (double i = 0; i < 999999999999; i++)
{
x += i;
str += i.ToString();
}

Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,(Action)(() => {

button3.Enabled = true;
button3.Text = x.ToString();
pictureBox1.Visible = false;
}));

嘶吼的蚂蚁 2012-09-13
  • 打赏
  • 举报
回复
哎,拯救不了你!~pictureBox1.ImageLocation=@"D:\a.jpg";居然技术分比我还多!~
嘶吼的蚂蚁 2012-09-13
  • 打赏
  • 举报
回复
你自己的代码没有把图片放到pictureBox1中啊。
yumanqing 2012-09-13
  • 打赏
  • 举报
回复
还是不行啊
yumanqing 2012-09-13
  • 打赏
  • 举报
回复
楼上的方法好像也不行啊。。。继续等待
嘶吼的蚂蚁 2012-09-13
  • 打赏
  • 举报
回复

private void button3_Click(object sender, EventArgs e)
{
//try
//{
pictureBox1.Visible = true; //这里显示不出来

System.Threading.Thread.Sleep(200);

Thread th = new Thread(delegate()
{
ttt();
});
th.Start();





//pictureBox1.Visible = false;

//}
//catch()
//{}
//finally
//{}
}

private void ttt()
{
button3.Enabled = false;
string str = "";
for (double i = 0; i < 999999999999; i++)
{
x += i;
str += i.ToString();
}
button3.Enabled = true;
button3.Text = x.ToString();
pictureBox1.Visible = false;
}
嘶吼的蚂蚁 2012-09-13
  • 打赏
  • 举报
回复

private void button3_Click(object sender, EventArgs e)
{
//try
//{
pictureBox1.Visible = true; //这里显示不出来

System.Threading.Thread.Sleep(200);

Thread th = new Thread(delegate()
{
ttt();
});
th.Start();





//pictureBox1.Visible = false;

//}
//catch()
//{}
//finally
//{}
}

private void ttt()
{
button3.Enabled = false;
string str = "";
for (double i = 0; i < 999999999999; i++)
{
x += i;
str += i.ToString();
}
button3.Enabled = true;
button3.Text = x.ToString();
pictureBox1.Visible = false;
}

110,545

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧