protected void Button1_Click(object sender, EventArgs e)
{
Thread.Sleep(1000);
string sHTML = Editor1.Text.Replace("'", "''");
OracleConnection con = new OracleConnection(this.conStr);
con.Open();
string sql = "insert into temp_yj_html html values ('" + sHTML + "')";
OracleCommand cmd = new OracleCommand(sql, con);
cmd.ExecuteNonQuery();
cmd.Dispose();
con.Close();
con.Dispose();
Label2.Text = "更新成功!";
Label2.Visible = true;
Label1.Text = "1";
System.Threading.Thread th = new System.Threading.Thread(new System.Threading.ThreadStart(sLabel));
th.Priority = ThreadPriority.Highest;
th.Start();
}
private void sLabel()
{
Thread.Sleep(1000);
Label1.Text = "2";
Label2.Visible = false;
}
我想在显示“更新成功”1秒后让它消失。线程th调用sLabel是成功的(已经测试),但是sLabel里面Thread.Sleep(1000);
以后的代码没有执行。
{
Thread.Sleep(1000);
string sHTML = Editor1.Text.Replace("'", "''");
OracleConnection con = new OracleConnection(this.conStr);
con.Open();
string sql = "insert into temp_yj_html html values ('" + sHTML + "')";
OracleCommand cmd = new OracleCommand(sql, con);
cmd.ExecuteNonQuery();
cmd.Dispose();
con.Close();
con.Dispose();
Label2.Text = "更新成功!";
Label2.Visible = true;
Label1.Text = "1";
System.Threading.Thread th = new System.Threading.Thread(new System.Threading.ThreadStart(sLabel));
th.Priority = ThreadPriority.Highest;
th.Start();
}
private void sLabel()
{
Thread.Sleep(1000);
Label1.Text = "2";
Label2.Visible = false;
}
我想在显示“更新成功”1秒后让它消失。线程th调用sLabel是成功的(已经测试),但是sLabel里面Thread.Sleep(1000);
以后的代码没有执行。
解决方案 »
- winform怎样在一个界面中显示多重功能
- 快速把ListView数据导出至EXCEL 别拿复制过的代码发
- 数据库开关效率问题
- c# 对于图片处理的问题
- 关于写文件的一点问题
- Int转换成Enum的疑问
- winform中的Form.Resize事件总是比Form.Control.Resize事件后触发,有什么办法让Form.Resize事件先触发呢?
- 在comboBox中输入汉字的首字母 检索自己定义的字库
- System.Threading.Timer
- c# tcptraceroute源代码
- 高分求webpart 中控件事件解决方案,比如多个DropDownList连动
- C#写入数据到mysql数据库,这段代码哪里有问题?请教各位!
private void sLabel()
{
Thread.Sleep(1000);
this.Invoke(new ThreadStart(Reset));
}private void Reset()
{
Label1.Text = "2";
Label2.Visible = false;
}
Label1是在主线程中生成的
在.NET 2.0中应该有提示的
在线等,解决的还可散分~~
那你为什么不用js!!!!!
settimeout(1000);
js都是封装好的,后台代码不能调用前台js。
我也试了控件的客户端触发,但是就是调用不上。急啊~~
转的:http://www.blogjava.net/SIDNEY/archive/2008/07/07/213031.html
你看看,肯定可以解决你的问题delegate void aa(string s);//创建一个代理 private void pri(string t)//这个就是我们的函数,我们把要对控件进行的操作放在这里 { if (!richTextBox1.InvokeRequired)//判断是否需要进行唤醒的请求,如果控件与主线程在一个线程内,可以写成if(!InvokeRequired) { MessageBox.Show("同一线程内"); richTextBox1.Text =t; } else { MessageBox.Show("不是同一个线程"); aa a1 =new aa(pri); Invoke(a1,new object []{t});//执行唤醒操作 } } private void Form1_Load(object sender, System.EventArgse) { Thread newthread = new Thread(new ThreadStart(ttread)); newthread.Start(); } void ttread() { pri("sdfs"); }
我写的是WEB程序~~希望能够有高人指点小弟一下。跪谢啦!!
晕死的~~
根本不需要用线程,timer完全可以实现啊,线程不是万能的,能不用最好不要
不用急,你的问题很初级,但这是你必须要经历的过程