码迷,mamicode.com
首页 > 编程语言 > 详细

c# 线程问题

时间:2019-09-02 13:45:05      阅读:89      评论:0      收藏:0      [点我收藏+]

标签:ret   method   data   control   else   sdi   hand   erro   public   

          //子线程调用主线程方法一
                                //this.Invoke(new Action(() => {
                                //    dgvScanChip.DataSource = SaveChipList;
                                //}));
                                //子线程调用主线程方法一
                                //ControlInvoker.Invoke(this, delegate
                                //{
                                //    dgvScanChip.DataSource = SaveChipList;
                                //});

 

 

 public static class ControlInvoker
    {
        private static readonly Logger logger = LogManager.GetLogger("DefaultLog");
        public static void Invoke(Control ctl, MethodInvoker method)
        {
            try
            {
                if (!ctl.IsHandleCreated)
                    return;

                if (ctl.IsDisposed)
                    return;

                if (ctl.InvokeRequired)
                {
                    ctl.Invoke(method);
                }
                else
                {
                    method();
                }
            }
            catch (Exception ex)
            {
                logger.Error(ex, "ControlInvoker异常");
            }

        }
    }

c# 线程问题

标签:ret   method   data   control   else   sdi   hand   erro   public   

原文地址:https://www.cnblogs.com/ruiyuan/p/11445708.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!