每隔60秒刷新一次Windows窗体的线程 [英] Thread to refresh a windows form every 60 seconds
本文介绍了每隔60秒刷新一次Windows窗体的线程的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在开发一个Windows应用程序。
我需要每60秒刷新一次表格。
我知道这可以通过一个帖子来实现但是我不是找到方法。
真的很感激,如果有人能给我提供示例代码。
提前谢谢!
Hi,
I am working on a windows application.
I need one of my forms to be refreshed every 60 seconds.
I know this can be implemented through a thread but I am not finding a way.
Really appreciate if anyone could provide me with a sample code.
Thanks in advance!
推荐答案
为什么是线程?如果您确实需要这样做,请设置一个类级别的Timer,间隔为60秒,并在Tick事件中进行刷新。
Why a thread? If you really need this to occur, set up a class level Timer, with an interval of 60 Seconds, and do the refresh in the Tick event.
Timer refreshTimer = new Timer();
...
refreshTimer.Interval = 60000; //60 seconds in milliseconds
refreshTimer.Tick += new EventHandler(refreshTimer_Tick);
refreshTimer.Start();
...
void refreshTimer_Tick(object sender, EventArgs e)
{
Invalidate();
}
之后拿一个定时器控件
表单加载
{....
timer1.Interval = 60000;
timer1.Start();
}
创建一个变量= static int t1 = 0;
On timer tick事件
private void timer1_Tick(object sender,EventArgs e)
{
if(t1 == 0)
{
//去更新任何东西
t1 = 1 ;
}
其他
{
//更新任何内容<
t1 = 0;
}
}
Take a Timer Control after that
on the form load
{....
timer1.Interval = 60000;
timer1.Start();
}
creat a variable = static int t1 = 0;
On timer tick event
private void timer1_Tick(object sender, EventArgs e)
{
if (t1 == 0)
{
// Go Update anything
t1 = 1;
}
else
{
// Go update anything<
t1 = 0;
}
}
这篇关于每隔60秒刷新一次Windows窗体的线程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文