想了一会儿,觉得这个问题值得思考,C#多线程操作 /*使程序每隔一段时间就弹出一个对话框*/ public partial class Form1 : Form { Thread testThread; ThreadStart testStart; public Form1() { InitializeComponent(); //构造线程以及初始化 testStart = new ThreadStart(Reminder);
//调用线程(这么做实在是有点浪费资源,我一时没想到方法了) for (int i = 0; i < 5; i++) { testThread = new Thread(testStart); testThread.Start(); //在Sleep函数中添加需要的休息时间 Thread.Sleep(2000); testThread.Abort(); } } /// <summary> /// Reminder函数为实际添加的检查数据库中数据的代码 /// </summary> public void Reminder() { MessageBox.Show("The message is from Microsoft Corp."); } }
while(true) { //数据库的操作语句 Thread.Sleep(你设定的时间); }This method is not so good.
while(true)
{
//数据库的操作语句
Thread.Sleep(你设定的时间);
}
public partial class Form1 : Form
{
Thread testThread;
ThreadStart testStart; public Form1()
{
InitializeComponent();
//构造线程以及初始化
testStart = new ThreadStart(Reminder);
//调用线程(这么做实在是有点浪费资源,我一时没想到方法了)
for (int i = 0; i < 5; i++)
{
testThread = new Thread(testStart);
testThread.Start();
//在Sleep函数中添加需要的休息时间
Thread.Sleep(2000);
testThread.Abort();
}
} /// <summary>
/// Reminder函数为实际添加的检查数据库中数据的代码
/// </summary>
public void Reminder()
{
MessageBox.Show("The message is from Microsoft Corp.");
} }
{
//数据库的操作语句
Thread.Sleep(你设定的时间);
}This method is not so good.
timer控件;
或:
setInterval()
<script type="text/javascript">
function go()
{
document.getElementById("Button1").click();
}
setInterval("go()",10000);//setTimeout只执行一次
</script>