关于C#的问题~

来源:百度知道 编辑:UC知道 时间:2024/06/05 01:37:47
有有个按扭

怎么编写代码可以按按按扭后..先过3秒钟才执行 DirectoryInfo bbq = new DirectoryInfo(k);
晕....我在举例啊~~~~

比如那是代码.

用Timer:

执行完第一次后停滞Timer就可以了。如果你希望执行若干次的话,加一个计数器并判断次数即可:)

PageLoad事件的代码:
private Timer timer = new Timer();

private void Page_Load(object sender, EventArg e)
{
if(!IsPostBack)
{
timer.Interval = 3000;
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}
}

如果是FormLoad:
private Timer timer = new Timer();

private void Form1_Load(object sender, EventArgs e)
{
timer.Interval = 3000;
timer.Tick += new EventHandler(timer_Tick);
timer.Start();
}

下面的都一样
private void timer_Tick(object sender, EventArgs e)
{
DirectoryInfo bbq = new DirectoryInfo(k);
timer.Stop();
}

用线程:
System.Threading.Thread th = new System.Threading.Thread(new System.Threading.ThreadStart(Some));
th.Sleep(3000);
th.Start();

private void Some()
{
DirectoryInfo bbq = new DirectoryInfo(k);
}

不建议自