日期:2014-05-17 浏览次数:21048 次
private void Form1_Load(object sender, EventArgs e) { while (true) { Thread t = new Thread(new ThreadStart(test)); t.Start(); Thread.Sleep(1000); } } private void test() { MessageBox.Show("hello1"); }
------解决方案--------------------
pirvate bool bStop = false; private void Form1_Load(object sender, EventArgs e) { Thread td = new Thread(new ThreadStart(test)); td.Start(); } private void test() { while(!bStop) { //这边进行你的扫描数据库操作 Thread.Sleep(60 * 1000); } } private void stop() { bStop = true; }
------解决方案--------------------
private void btnSave_Click(object sender, EventArgs e) { try { ThreadPool.QueueUserWorkItem(new WaitCallback(AutoLoad)); } catch(Exception ex) { MessageBox.Show(ex.Message + "\r\n" + ex.StackTrace); } } private void AutoLoad(object ob) { while(true) { //do... Thread.Sleep(1000*60); } }