C#Thread 使用后台 线程定时刷新 线程的使用 Thread的使用

private static Thread th; 
 
        /// <summary>
        /// 初始化
        /// </summary>
        public static void Init()
        {
            th = new Thread(ThFun);
            th.IsBackground = true;//设为 后台线程
            th.Start();
        } 
        private static void ThFun()
        {
            try
            {
                while (true)
                { 
                    //执行方法()  ;
                    Thread.Sleep(300000);//每五分钟刷新一次   以毫秒为单位
                }
            }
            catch { }
        }


原文:https://blog.csdn.net/a770kfof/article/details/53067489 

private void ThreadDemo()

{

   new Thread(() =>
            {
                while (true)
                {
                    try
                    {
                        OnThreadCheckUser();//要执行的方法
                    }
                    catch{}
                    Thread.Sleep(1000);
                }
            }) { IsBackground = true }.Start();

}

  private void OnThreadCheckUser()
  {
            MessageBox.Show("你需要的内容");

  }


 

猜你喜欢

转载自blog.csdn.net/cn_514/article/details/89670342