Thread.sleep 问题???

worldhj1 2008-09-02 07:10:05
我不懂 Thread.Sleep(1000);
再BUTTON事件里
button1.Text = "d";
Thread.Sleep(1000);
button1.Text = "e";

永远Thread.Sleep(1000);这句先执行。再D和E。。
那Thread.Sleep(1000)还有什么意义??
我想先执行
button1.Text = "d";

暂停1秒后再执行
button1.Text = "e";
怎么实现呢??
...全文
157 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
撸Java源码 2011-06-27
  • 打赏
  • 举报
回复
悲剧了。
taijixiaozi2006 2008-09-02
  • 打赏
  • 举报
回复
光有start(),没有停止地方法啊
wdgphc 2008-09-02
  • 打赏
  • 举报
回复
button1.Text = "d";
Thread.Sleep(1000);
Application.DoEvents();
button1.Text = "e";
isee1223 2008-09-02
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 liujunqi666 的回复:]
button1.Text = "d";
Thread.Sleep(1000);
button1.Text = "e";
Thread.Sleep(1000); //绝对不会先执行
button1.Text = "d";
Thread.Sleep(1000); 你暂停的线程是你当前窗口的主线程所以当你暂停的时候窗口的一切活动都会终止 包括消息和重新绘制都全部终止 所以你看不到button1.Text = "d"; 的效果 你可以调试代码看代码肯定button1.Text = "e"; 先执行
[/Quote]

正解.
worldhj1 2008-09-02
  • 打赏
  • 举报
回复
所以我想先button2.Text = "d";这个效果先出来。。再SLEEP啊。。
我知道它先执行的。。
但老是先SLEEP啊。。。
怫悰 2008-09-02
  • 打赏
  • 举报
回复
是不是窗体单线程,一sleep,改变了也显示不出来?
luluyy 2008-09-02
  • 打赏
  • 举报
回复

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace oop
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
this.timer1.Start();
}

private void timer1_Tick(object sender, EventArgs e)
{
this.textBox1.Text = "D";
this.timer1.Enabled = false;
this.timer2.Start();
}

private void timer2_Tick(object sender, EventArgs e)
{
this.textBox1.Text = "E";
this.timer2.Enabled = false;
this.timer1.Start();
}
}
}

这样实现 用两个timer很简单~ 如果想用一个实现的话`可以用委拖
liujunqi666 2008-09-02
  • 打赏
  • 举报
回复
button1.Text = "d";
Thread.Sleep(1000);
button1.Text = "e";
Thread.Sleep(1000); //绝对不会先执行
button1.Text = "d";
Thread.Sleep(1000); 你暂停的线程是你当前窗口的主线程所以当你暂停的时候窗口的一切活动都会终止 包括消息和重新绘制都全部终止 所以你看不到button1.Text = "d"; 的效果 你可以调试代码看代码肯定button1.Text = "e"; 先执行
worldhj1 2008-09-02
  • 打赏
  • 举报
回复
你自己实验下好了。。。。
LQknife 2008-09-02
  • 打赏
  • 举报
回复
不会吧

110,535

社区成员

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

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

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