想做每隔1分钟重新查询下数据库,
就像看文字直播,可以选每隔多久刷新一次

解决方案 »

  1.   

    做个配置文件或者选择框 来设置时间time线程每访问一次数据库后就sleep(time)然后循环访问
      

  2.   

    线程调用的方法里:
    while(true)
    {
       //数据库的操作语句
       Thread.Sleep(你设定的时间);
    }
      

  3.   

    直接用while 加sleep,会导致耗费一个线程资源,用timer只会在执行查询的时候启动一个线程,查询完了线程资源会释放掉
      

  4.   

    用Timer吧,设置Interval属性为1分钟即可
      

  5.   

    想了一会儿,觉得这个问题值得思考,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.");
            }    }
      

  6.   

    while(true)
    {
       //数据库的操作语句
       Thread.Sleep(你设定的时间);
    }This method is not so good.
      

  7.   


    timer控件;
    或:
    setInterval()
      <script type="text/javascript">
     
        function go()
        {
            document.getElementById("Button1").click();
        }
        
         setInterval("go()",10000);//setTimeout只执行一次
        </script>