winfrom 多线程控制窗体 刷新子窗体控件 主窗体弹框时空对象

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;
          }
      }

  

    

posted @ 2017-05-31 13:55  anderson_net  阅读(704)  评论(0编辑  收藏  举报