- private Thread MyThread;//自定义全局线程
- /// <summary>
- /// showDefaultItems 展示默认元素
- /// </summary>
- private void DoMonitor()
- {
- Action ac = new Action(showDefaultItems);
- MyThread = new Thread(() => {
- DateTime lsDT = File.GetLastWriteTime(ResourceConfig.DefaultXmlPath);
- DateTime newDT;
- while (true)
- {
- newDT=File.GetLastWriteTime(ResourceConfig.DefaultXmlPath);
- if (newDT!=lsDT)
- {
- lsDT = newDT;
- this.Invoke(ac);
- }
- Thread.Sleep(1000);
- }
- });
- MyThread.Name = "监控后台程序";
- MyThread.Priority = ThreadPriority.Normal;
- MyThread.Start();
- }
- //该片段来自于http://www.codesnippet.cn/detail/2707201614892.html
来源: http://www.codesnippet.cn/detail/2707201614892.html