汕头百城求职网:.net(C#)如何实现一段15秒的时间间隔,比如单击某按钮后15秒后让Label1.text="fdd"?

来源:百度文库 编辑:杭州交通信息网 时间:2024/04/30 15:25:31
最好有代码(web)如果在page_load里写(thread好象不行)

给你个DEMO
//*********************** ThreadTest.cs ********************
using System;
using System.Threading;
class ThreadTest
{
public static void threadMethod()
{
for (int i=0; i<10; i++)
{
Console.WriteLine("threadMethod: {0}", i);
Thread.Sleep(1);
}
}
public static void Main()
{
Console.WriteLine("Main()线程: 启动第2个线程");
Thread thread=new Thread(new ThreadStart(threadMethod));
thread.Start();
for (int i=0; i<4; i++)
{
Console.WriteLine("Main()线程: 运行 #{0} 项工作",i);
Thread.Sleep(0);
}
Console.WriteLine("Main()线程: 调用 Join() 方法\n" +
" 等待 threadMethod() 执行完毕");
thread.Join();
Console.WriteLine("Main()线程: threadMethod.Join 已" +
"经运行完毕");
}
}

用线程的.Sleep(15)方法,或者用Timer来实现

可以用timer控件!

用脚本的方法
<script>
function setvalue()
{
setTimeout("window.document.all.Label1.innerHTML='fdd'",15000);
}
</scirpt>
<input type=button onclick="setvalue()">