Beispiel #1
0
        void autoUpdater1_UpdateProgress(object sender, SinoSZJS.Base.UpdateProgessEventArgs e)
        {
            //MethodInvoker invoker = new MethodInvoker(UpdateProgress);
            //synchronizer.Invoke(invoker, new object[] { e.Message});

            System.ComponentModel.ISynchronizeInvoke synchronizer = this;
            progressEventHandle invoker = new progressEventHandle(UpdateProgress);

            synchronizer.BeginInvoke(invoker, new object[] { e.Message });
        }
        /// <summary> 根据线程选择是否异步执行 </summary>
        public static void DoThread <T>(this EventHandler handle, EventArgs args)
        {
            if (handle == null)
            {
                return;
            }

            if (handle.Target is System.ComponentModel.ISynchronizeInvoke)
            {
                System.ComponentModel.ISynchronizeInvoke aSynch = handle.Target as System.ComponentModel.ISynchronizeInvoke;

                if (aSynch.InvokeRequired)
                {
                    object[] a = new object[] { handle, args };
                    // Todo :检查是否异步调用
                    aSynch.BeginInvoke(handle, a);
                }
                else
                {
                    // Todo :检查同步调用
                    handle(handle, args);
                }
            }
        }