在线程中调用其它主界面的模块,因为中间有休息1000ms,所以调用前要检查DateTimeRun变量;在From_load 启动线程;在From_closing From_closed 设置DateTimeRun=false

//系统启动后,自动启动时钟

        void jishi_kernel()

        {

            try

            {

                while (DateTimeRun)

                {

                    Thread.Sleep(1000);



                    if (myRunning)

                        Runni_time++;

                    else

                        Pasue_time++;



                    if (DateTimeRun) /* 程序的核心,否则报错;DateTimeRun为false后,这句话还可能被调用;在Form_closing前置DateTimeRun=false*/

                        this.Invoke(new ShowMessageMethod(ShowMessage), Runni_time, Pasue_time); //正常和非正常计时



                }

            }

            catch (System.ObjectDisposedException ee)

            {

                MessageBox.Show("错误1:" + ee.ToString());

            }

            catch (System.Exception ee)

            {

                MessageBox.Show("错误2:" + ee.ToString());

            }

        }

 

你可能感兴趣的:(DateTime)