当前位置: 首页>>代码示例>>C#>>正文


C# this.BeginInvoke方法代码示例

本文整理汇总了C#中this.BeginInvoke方法的典型用法代码示例。如果您正苦于以下问题:C# this.BeginInvoke方法的具体用法?C# this.BeginInvoke怎么用?C# this.BeginInvoke使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在this的用法示例。


在下文中一共展示了this.BeginInvoke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Invoke

        public static void Invoke(this Control uiElement, Action updater, bool forceSynchronous = true)
        {
            if (uiElement == null)
            {
                throw new ArgumentNullException("uiElement");
            }

            if (uiElement.InvokeRequired)
            {
                if (forceSynchronous)
                {
                    try
                    {
                        uiElement.Invoke((Action)delegate { Invoke(uiElement, updater, forceSynchronous); });
                    }
                    catch (Exception e) { }
                }
                else
                {
                    uiElement.BeginInvoke((Action)delegate { Invoke(uiElement, updater, forceSynchronous); });
                }
            }
            else
            {
                if (!uiElement.IsDisposed)
                {
                    updater();
                }
            }
        }
开发者ID:CheeseSoftware,项目名称:MasterBot,代码行数:30,代码来源:SafeInvoke.cs

示例2: Invoke

 public static void Invoke(this UserControl c, Action a)
 {
     if (!c.InvokeRequired)
         a();
     else if (!c.IsDisposed && !c.Disposing && c.Created)
         c.BeginInvoke(a);
 }
开发者ID:JohnMcCaffery,项目名称:ChimeraClean,代码行数:7,代码来源:InvokeExtension.cs

示例3: InvokeOnUiThreadIfRequired

 /*
  * Executes the action asynchronously on the UI thread, without blocking the calling thread.
  */
 internal static void InvokeOnUiThreadIfRequired(this Control control, Action action) {
     if(control.InvokeRequired) {
         control.BeginInvoke(action);
     } else {
         action.Invoke();
     }
 }
开发者ID:bewbaloo,项目名称:SlackUI,代码行数:10,代码来源:ControlExtension.cs

示例4: BeginInvokeAfterTimeout

        /// <summary>
        /// Executes the specified action asynchronously on the thread the Dispatcher is associated with, after the specified timeout.
        /// </summary>
        /// <param name="dispatcher">The dispatcher instance.</param>
        /// <param name="timeout">The <see cref="TimeSpan"/> representing the amount of time to delay before the action is invoked.</param>
        /// <param name="action">The <see cref="Action"/> to execute.</param>
        public static void BeginInvokeAfterTimeout(this Dispatcher dispatcher, TimeSpan timeout, Action action)
        {
            if (!dispatcher.CheckAccess())
            {
                dispatcher.BeginInvoke(() => dispatcher.BeginInvokeAfterTimeout(timeout, action));
            }
            else
            {
                var dispatcherTimer = new DispatcherTimer()
                {
                    Interval = timeout
                };

                dispatcherTimer.Tick += (s, e) =>
                {
                    dispatcherTimer.Stop();

                    dispatcherTimer = null;

                    action();
                };

                dispatcherTimer.Start();
            }
        }
开发者ID:HamGuy,项目名称:Cimbalino-Phone-Toolkit,代码行数:31,代码来源:DispatcherExtensions.cs

示例5: FireAndForget

 public static void FireAndForget(this Action action, object state = null)
 {
     lock (_invokedActions)
     {
         _invokedActions.Add(action.BeginInvoke(Forget, state), action);
     }
 }
开发者ID:DanMannMann,项目名称:Toolkit,代码行数:7,代码来源:ActionExtensions.cs

示例6: InvokeAsynchronouslyInBackground

 /// <summary>
 /// A simple threading extension method, to invoke a delegate
 /// on the correct thread asynchronously if it is not currently 
 /// on the correct thread which can be used with DispatcherObject types.
 /// </summary>
 /// <param name="dispatcher">The Dispatcher object on which to 
 /// perform the Invoke</param>
 /// <param name="action">The delegate to run</param>
 public static void InvokeAsynchronouslyInBackground(this Dispatcher dispatcher, Action action)
 {
     if (dispatcher != null)
         dispatcher.BeginInvoke(DispatcherPriority.Background, action);
     else
         action();
 }
开发者ID:AuditoryBiophysicsLab,项目名称:ESME-Workbench,代码行数:15,代码来源:DispatcherExtensions.cs

示例7: SafeInvoke

 /// <summary>
 /// Функция упрощающая использование Invoke() для Windows Forms приложений
 /// </summary>
 /// <param name="ctrl">Элемент управления для которого необходимо вызвать Invoke()</param>
 /// <param name="cmd"></param>
 /// <example>myCtrl.SafeInvoke(() => myCtrl.Enabled = false);</example>
 public static void SafeInvoke(this Control ctrl, Action cmd)
 {
     if (ctrl.InvokeRequired)
         ctrl.BeginInvoke(cmd);
     else
         cmd();
 }
开发者ID:bazile,项目名称:Training,代码行数:13,代码来源:SafeInvoker.cs

示例8: PerformOnMainThread

 public static void PerformOnMainThread(this Control control, Action action)
 {
     if (control.InvokeRequired)
         control.BeginInvoke(action);
     else
         action();
 }
开发者ID:SyncZone,项目名称:WinFormHelper,代码行数:7,代码来源:ControlExtend.cs

示例9: SetText

 /// <summary>
 /// Set text to the control thread-safely.
 /// </summary>
 /// <param name="c"></param>
 /// <param name="m"></param>
 public static void SetText(this Control c, string m)
 {
     if (c.InvokeRequired)
         c.BeginInvoke(new MethodInvoker(() => { c.Text = m; }));
     else
         c.Text = m;
 }
开发者ID:sergeystoyan,项目名称:CliverBot,代码行数:12,代码来源:BaseForm.cs

示例10: adoptAsync

 public static void adoptAsync(this Dispatcher dispatcher, Action del)
 {
     if(dispatcher.CheckAccess())
         del();
     else
         dispatcher.BeginInvoke(del);
 }
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:7,代码来源:DispatcherExtensions.cs

示例11: adoptAsync

 public static void adoptAsync(this Dispatcher dispatcher, Action del)
 {
     if (Thread.CurrentThread == dispatcher.Thread)
         del();
     else
         dispatcher.BeginInvoke(del);
 }
开发者ID:StackableRegiments,项目名称:metl2011,代码行数:7,代码来源:DispatcherExtensions.cs

示例12: BeginInvoke

 public static void BeginInvoke(this Control control, Action action)
 {
     if (control.InvokeRequired)
         control.BeginInvoke(action);
     else
         action();
 }
开发者ID:luisflv,项目名称:SistemasDistribuidos,代码行数:7,代码来源:Controle.cs

示例13: SafeInvoke

        public static void SafeInvoke(this Control ui_element,
            Action updater, bool force_synchronous)
        {
            if (ui_element == null)
                return;

            if (ui_element.InvokeRequired) {
                if (force_synchronous) {
                    ui_element.Invoke ((Action) delegate {
                        SafeInvoke (ui_element, updater, force_synchronous);
                    });

                } else {
                    ui_element.BeginInvoke ((Action) delegate {
                        SafeInvoke (ui_element, updater, force_synchronous);
                    });
                }

            } else {
                if (ui_element.IsDisposed)
                    throw new ObjectDisposedException ("Control is already disposed.");

                updater ();
            }
        }
开发者ID:nicolaslazartekaqui,项目名称:SparkleShare,代码行数:25,代码来源:SparkleStatusIcon.cs

示例14: BeginInvoke

 public static void BeginInvoke(this Control c, MethodInvoker code)
 {
     //c.BeginInvoke(code);
     if (c.InvokeRequired)
         c.BeginInvoke(code);
     else
         c.Invoke(code);
 }
开发者ID:sergeystoyan,项目名称:FhrCliverHost,代码行数:8,代码来源:BaseForm.cs

示例15: BeginInvokeIfRequired

 public static void BeginInvokeIfRequired(this Control control, MethodInvoker action)
 {
     if (control.InvokeRequired) {
     control.BeginInvoke(action);
       } else {
     action();
       }
 }
开发者ID:qida,项目名称:qcv,代码行数:8,代码来源:Control.cs


注:本文中的this.BeginInvoke方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。