Invoke() public method

public Invoke ( Delegate method, object args ) : object
method Delegate
args object
return object
        bool Reinvoke <T>(object sender, T e, EventHandler <T> handler)
            where T : EventArgs
        {
            if (Synchronizer != null && Synchronizer.InvokeRequired)
            {
                Synchronizer.Invoke(handler, new object[] { sender, e });
                return(true);
            }

            return(false);
        }
Esempio n. 2
0
 /// <summary>
 /// 输出日志【允许非UI线程直接调用】
 /// </summary>
 /// <param name="message">要输出的消息</param>
 public void OutputLog(MessageItem message)
 {
     Synchronizer.Invoke(() =>
     {
         Messages.Insert(0, message);
         if (Messages.Count > MaxMessageCount)
         {
             for (int i = MaxMessageCount; i >= MaxMessageCount - RemoveItemsCount; i--)
             {
                 Messages.RemoveAt(i);
             }
         }
     });
 }
Esempio n. 3
0
        protected virtual void OnRaisePropertyChanged <T>(string propertyName, T previousValue, T actualValue)
        {
            var action = new Action <string, T, T>((pro, pre, act) => {
                PropertyChangedEvent?.Invoke(this, new PropertyChangedEventArgs(pro));
                PropertyChanged?.Invoke(this as TNotifier, new NotifierPropertyChangedEventArgs <TNotifier>(pro, (TNotifier)(INotifier <TNotifier>) this, pre, act));
            });

            if (UseSynchronizerOnRaisePropertyChanged && Synchronizer != null)
            {
                Synchronizer.Invoke(action, propertyName, previousValue, actualValue).Wait();
            }
            else
            {
                action(propertyName, previousValue, actualValue);
            }
        }
Esempio n. 4
0
 protected ConnectableNotifier()
 {
     PropertyChanged += (s, e) =>
     {
         e.Case(() => KeepAliveInterval, p =>
         {
             //Si KeepAliveInterval es menor que 1 lanzo una ArgumentException
             if (p.ActualValue.TotalMilliseconds < 1)
             {
                 throw new ArgumentException(
                     "El valor de '" + s.GetMemberName(() => s.KeepAliveInterval) + "' no puede ser cero o negativo, para deshabilitar el KeepAlive establezca la propiedad '" + s.GetMemberName(() => s.IsKeepAliveEnable) + "' en False.",
                     s.GetMemberName(() => s.KeepAliveInterval));
             }
         });
         e.Case(() => ConnectionMode, p =>
         {
             //Si cambia el modo de conexión a automática y no estoy conectado o conectando debo llamar a Connect
             if (p.ActualValue == ConnectionMode.Automatic && State != ConnectionState.Opened && State != ConnectionState.Opening)
             {
                 Connect();
             }
         });
         e.Case(() => State, p =>
         {
             //Si cambia el estado hacia o desde Opened abrá que disparar el cambio de la propiedad IsConnected y el evento IsConnectedChanged
             if (p.PreviousValue == ConnectionState.Opened || p.ActualValue == ConnectionState.Opened)
             {
                 RaisePropertyChanged(() => IsConnected, p.PreviousValue == ConnectionState.Opened, p.ActualValue == ConnectionState.Opened);
                 if (Synchronizer != null)
                 {
                     Synchronizer.Invoke(actualValue => IsConnectedChanged?.Invoke(this, new EventArgs <bool>(actualValue == ConnectionState.Opened)), p.ActualValue);
                 }
                 else
                 {
                     IsConnectedChanged?.Invoke(this, new EventArgs <bool>(p.ActualValue == ConnectionState.Opened));
                 }
             }
         });
     };
 }
Esempio n. 5
0
 /// <summary>
 ///     This executes a delegate on the thread hosting this object.
 /// </summary>
 /// <param name="method">
 ///     The delegate to execute.
 /// </param>
 /// <param name="args">
 ///     The arguments to pass to the delegate.
 /// </param>
 /// <returns>
 ///     The object returned by the delegate.
 /// </returns>
 public object Invoke(Delegate method, object[] args)
     {
         return Synchronizer.Invoke(method, args);
     }
Esempio n. 6
0
        void configAutoUpdate()
        {
            _updater = Updater.CreateUpdaterInstance(Properties.Settings.Default.AutoUpdateUri, "update_c.xml");

            //开启时做一次检查
            _updater.Context.EnableEmbedDialog = false;
            _updater.Context.AutoKillProcesses = false;

            _updater.Error += (sender, e) =>
            {
                logError("自动更新时发生错误:" + _updater.Context.Exception.Message, _updater.Context.Exception);
            };

            _updater.UpdatesFound += (sender, e) =>
            {
                _autoUpdateTimer.Stop();

                //保存上次运行的服务配置
                SaveLastRunningConfig();

                //刷新一次服务状态
                refreshServicesStatus();

                //给于半分钟时间等待所有服务退出
                int i;
                for (i = 0; i < 10; i++)
                {
                    foreach (var controllableUI in _serviceUIs)
                    {
                        controllableUI.Value.Stop();
                    }

                    System.Threading.Thread.Sleep(3000);

                    //刷新一次服务状态
                    refreshServicesStatus();

                    if (_serviceUIs.All(cui => cui.Value.IsStopped))
                    {
                        break;
                    }
                }

                if (i == 10)//等待超时
                {
                    logError("自动更新错误:等待服务关闭超时,将启用强制更新模式");
                    //尽量保存配置信息
                    SaveConfig();

                    //配置外部更新程序为强制结束进程模式
                    _updater.Context.AutoExitCurrentProcess       = true;
                    _updater.Context.AutoKillProcesses            = true;
                    _updater.Context.AutoEndProcessesWithinAppDir = true;
                    //启动外部更新程序
                    _updater.StartExternalUpdater();
                }
                else//所有服务正常关闭
                {
                    //启动更新进程
                    _updater.StartExternalUpdater();

                    //退出控制台
                    CanClose = true;
                    Synchronizer.Invoke(() => { Window.Close(); });
                }
            };

            if (!_updater.BeginCheckUpdateInProcess())
            {
                logError("开始检测更新时发生错误:" + _updater.Context.Exception.Message, _updater.Context.Exception);
            }

            _autoUpdateTimer          = new Timer(Properties.Settings.Default.AutoUpdateInterval * 1000);
            _autoUpdateTimer.Elapsed += (sender, e) =>
            {
                //自动升级检查
                if (!_updater.BeginCheckUpdateInProcess())
                {
                    logError("开始检测更新时发生错误:" + _updater.Context.Exception.Message, _updater.Context.Exception);
                }
            };

            _autoUpdateTimer.Start();
        }