如何让一个线程每10秒执行一次啊?我写在什么地方,窗体的load事件里可以吗?
做一个在线显示功能,有人上线就即时显示,我想每10秒就刷新一次,怎么做,写在什么地方?
 private void online()
        {
            listBox1.Items.Clear();
            MySqlDataAdapter data = con.xline(1);//查询在线
            MySqlDataAdapter da = con.xline(0);//查询不在线
            set = new DataSet();
            data.Fill(set, "biao1");
            da.Fill(set, "biao2");
            //在线人数  
            int count1 = set.Tables[0].Rows.Count;
            // 离线人数
            int count2 = set.Tables[1].Rows.Count;            listBox1.Items.Add("---在线人数" + count1 + "---");
            //添加在线用户名字
            for (int i = 0; i < set.Tables[0].Rows.Count; i++)
            {
                listBox1.Items.Add(set.Tables[0].Rows[i][0].ToString());
            }
            listBox1.Items.Add("---离线人数" + count2 + "---");
            //添加不在线用户名字
            for (int t = 0; t < set.Tables[1].Rows.Count; t++)
            {
                listBox1.Items.Add(set.Tables[1].Rows[t][0].ToString());
            }
        }用线程调用
   Thread thread = new Thread(new ThreadStart (online));
                       
  thread.Start();
Thread.Sleep(20);