1,这是因为用线程控制子窗体,刷新数据的时候会影响主窗体,因为主次窗体是以 Main man = new Main();  man.ShowDialog();形式存在

2,解决办法:

    新建公共类,Bool属性并赋值,在需要调用刷新数据方法地方通过给刷新数据的方法套一个事件,在通过Timer 控件结束当前线程后调用刷新数据

   代码: 

       

         public class Notify
        {
           public static bool IsImportSapFinished { get; set; }
        }

         System.Windows.Forms.Timer timer = new System.Windows.Forms.Timer();
         timer.Tick += new EventHandler(this.Monitor);
         timer.Interval = 1000;
         timer.Enabled = true;
         timer.Start();

 

         public void Monitor(object sender, EventArgs arg)
       {
           if (Notify.IsImportSapFinished)
          {
              GetDate();
              Notify.IsImportSapFinished = false;
          }
      }

  

    

版权声明:本文为anderson-net原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/anderson-net/p/6923812.html