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


C# MethodInvoker.Invoke方法代码示例

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


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

示例1: StartTry

 public static Thread StartTry(MethodInvoker code, ErrorHandler on_error = null, MethodInvoker on_finally = null, bool background = true)
 {
     Thread t = new Thread(
         () => {
             try
             {
                 code.Invoke();
             }
             catch (ThreadAbortException e)
             {
                 Thread.ResetAbort();
             }
             catch (Exception e)
             {
                 if (on_error != null)
                     on_error.Invoke(e);
                 else
                     Message.Error(e);
             }
             finally
             {
                 on_finally?.Invoke();
             }
         }
     );
     t.IsBackground = background;
     t.Start();
     return t;
 }
开发者ID:sergeystoyan,项目名称:CliverBot,代码行数:29,代码来源:ThreadRoutines.cs

示例2: ThreadSafeDelegate

 // Thread-safe operations from event handlers
 // I love StackOverflow: http://stackoverflow.com/q/782274
 public void ThreadSafeDelegate(MethodInvoker method)
 {
     if (InvokeRequired)
         BeginInvoke(method);
     else
         method.Invoke();
 }
开发者ID:crunchy234,项目名称:bglib,代码行数:9,代码来源:frmMain.cs

示例3: ActualizaProgressBar

 private void ActualizaProgressBar()
 {
     while (true)
     {
         MethodInvoker m = new MethodInvoker(() =>
         {
             int valor = progressBar.Value;
             if (valor == 100)
             {
                 valor = 0;
             }
             else
             {
                 ++valor;
             }
             progressBar.Value = valor;
             Thread.Sleep(milisegundos);
         });
         if (progressBar.InvokeRequired)
         {
             progressBar.Invoke(m);
         }
         else
         {
             m.Invoke();
         }
     }
 }
开发者ID:cedoduarte,项目名称:EjercicioThreads,代码行数:28,代码来源:Hilo.cs

示例4: UpdateState

 private void UpdateState()
 {
     MethodInvoker invoker = new MethodInvoker(delegate()
                 {
                     if ((File.GetAttributes(m_originalSolutionFullPath) & FileAttributes.ReadOnly) != 0)
                     {
                         m_labelState.ForeColor = Color.Red;
                         m_labelState.Text = "ReadOnly";
                         m_labelStateDescription.Visible = true;
                         m_buttonYes.Enabled = false;
                     }
                     else
                     {
                         m_labelState.ForeColor = Color.Black;
                         m_labelState.Text = "Writable";
                         m_labelStateDescription.Visible = false;
                         m_buttonYes.Enabled = true;
                     }
                 });
     if (m_labelState.InvokeRequired)
     {
         this.Invoke(invoker);
     }
     else
     {
         invoker.Invoke();
     }
 }
开发者ID:m3zercat,项目名称:slntools,代码行数:28,代码来源:UpdateOriginalSolutionForm.cs

示例5: BeginInvoke

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

示例6: Test_MethodInvoker_Basic

        public void Test_MethodInvoker_Basic()
        {
            var viewModel5 = new TestViewModel5();

            var canMethodInvoker = new MethodInvoker(new BindContext(viewModel5, "TestViewModel"), "CanAddAge", null);
            var methodInvoker = new MethodInvoker(new BindContext(viewModel5, "TestViewModel"), "AddAge", null);

            bool value = canMethodInvoker.CanInvoke();
            Assert.IsFalse(value);
            methodInvoker.Invoke();

            viewModel5.TestViewModel = new TestViewModel();
            value = canMethodInvoker.CanInvoke();
            Assert.IsTrue(value);
            methodInvoker.Invoke();

            Assert.AreEqual(1, viewModel5.TestViewModel.Age);

            var canMethodInvoker2 = new MethodInvoker(new BindContext(viewModel5, "TestViewModel"), "AddAge", null);

            MissingMemberException exception = null;
            try
            {
                canMethodInvoker2.CanInvoke();
            }
            catch (MissingMemberException e)
            {
                exception = e;
            }
            Assert.IsNotNull(exception);

            var vm = new TestViewModel();

            var canMethodInvoker3 = new MethodInvoker(new BindContext(viewModel5, "TestViewModel"), "CanSetAge",
                new[] { new BindContext(vm, "Age") });
            var methodInvoker2 = new MethodInvoker(new BindContext(viewModel5, "TestViewModel"), "SetAge",
                new[] { new BindContext(vm, "Age") });

            Assert.IsTrue(canMethodInvoker3.CanInvoke());
            vm.Age = 6;
            Assert.AreNotEqual(6, viewModel5.TestViewModel.Age);

            methodInvoker2.Invoke();
            Assert.AreEqual(6, viewModel5.TestViewModel.Age);
        }
开发者ID:zhouyongh,项目名称:BindingEngine,代码行数:45,代码来源:WeakMethodBindingTests.cs

示例7: InvokeInControlThread

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

示例8: UIThread

 public static void UIThread(this System.Windows.Forms.Control form, MethodInvoker code)
 {
     if (form.InvokeRequired)
     {
         form.Invoke(code);
         return;
     }
     code.Invoke();
 }
开发者ID:HakanL,项目名称:animatroller,代码行数:9,代码来源:Extensions.cs

示例9: UIThread

 /// <summary>
 /// Ensure code is run on the UI thread.
 /// </summary>
 internal static void UIThread(Control form, MethodInvoker code)
 {
     if (form.InvokeRequired)
     {
         form.Invoke(code);
         return;
     }
     code.Invoke();
 }
开发者ID:cixonline,项目名称:cixreader,代码行数:12,代码来源:Platform_Mono.cs

示例10: invoke_in_hosting_thread

 protected void invoke_in_hosting_thread(MethodInvoker code)
 {
     if (this.InvokeRequired)
     {
         this.Invoke(code);
         return;
     }
     code.Invoke();
 }
开发者ID:sergeystoyan,项目名称:FhrCliverHost,代码行数:9,代码来源:BaseControl.cs

示例11: InvokeMainWindow

 /// <summary>
 /// Invokes a method on the main window thread
 /// </summary>
 /// <param name="aInvoker">the method to invoke</param>
 /// <param name="aAsync">set to true to invoke asynchronously</param>
 private void InvokeMainWindow(MethodInvoker aInvoker, bool aAsync)
 {
     if (this.mPluginHost.MainWindow.InvokeRequired) {
     if (aAsync) {
       mPluginHost.MainWindow.BeginInvoke(aInvoker);
     } else {
       mPluginHost.MainWindow.Invoke(aInvoker);
     }
       } else {
     aInvoker.Invoke();
       }
 }
开发者ID:xenithorb,项目名称:KeeAgent,代码行数:17,代码来源:UIHelper.cs

示例12: guardedOp

 /// <summary>
 /// Executes a delegate and show exception window on exception
 /// </summary>
 private static void guardedOp(MethodInvoker mi)
 {
     try
     {
         mi.Invoke();
     }
     catch (Exception ex)
     {
         log.Error(ex);
         ExceptionDialog.showException(ex, "Dirigent Exception", "");
     }
 }
开发者ID:pjanec,项目名称:dirigent,代码行数:15,代码来源:MainFormHelpers.cs

示例13: FormAutoAnswer_Load

		private void FormAutoAnswer_Load(object sender, EventArgs e)
		{
			refresh = () =>
			{
				lsv.Items.Clear();
				foreach (var item in aa)
				{
					lsv.Items.Add(new ListViewItem(new string[]{
						item.Description,
						item.Prefix,
						item.Identify
					}));
				}
			};
			refresh.Invoke();
		}
开发者ID:kwedr,项目名称:acdown,代码行数:16,代码来源:FormAutoAnswer.cs

示例14: InvokeTest

        public void InvokeTest()
        {
            MethodInfo[] myMethodInfo;
            Type myType = typeof(MyClass);
            // Get the type and fields of FieldInfoClass.
            myMethodInfo = myType.GetMethods(BindingFlags.NonPublic | BindingFlags.Instance
                | BindingFlags.Public);

            MethodInfo methodInfo = myMethodInfo[0];

            IMethodInvoker target = new MethodInvoker(methodInfo);
            object instance = new MyClass("S001", "司法署");

            object expected = "S001";
            object actual;
            actual = target.Invoke(instance, null);
            Assert.AreEqual(expected, actual);
        }
开发者ID:felix-tien,项目名称:TechLab,代码行数:18,代码来源:MethodInvokerTest.cs

示例15: RenderThreadInvoke

        /// <summary>
        /// Special Invoke for framework callbacks from the render process.
        /// Maintains the thread within the context of the calling remote thread.
        /// Use this instead of invoke when the following conditions are meat:
        /// 1) The current thread is executing in the scope of a framework
        ///    callback event from the render process (ex. CfrTask.Execute).
        /// 2) You need to Invoke on the webbrowser control and
        /// 3) The invoked code needs to call into the render process.
        /// </summary>
        public void RenderThreadInvoke(MethodInvoker method)
        {
            if (!CfxRemoteCallContext.IsInContext)
            {
                throw new HtmlUIException("Can't use RenderThreadInvoke without being in the scope of a render process callback.");
            }

            if (!InvokeRequired)
            {
                method.Invoke();
                return;
            }

            var context = CfxRemoteCallContext.CurrentContext;

            // Use BeginInvoke and Wait instead of Invoke.
            // Invoke marshals exceptions back to the calling thread.
            // We want exceptions to be thrown in place.

            var waitLock = new object();
            lock (waitLock)
            {
                BeginInvoke((MethodInvoker)(() => {
                    context.Enter();
                    try
                    {
                        method.Invoke();
                    }
                    finally
                    {
                        context.Exit();
                        lock (waitLock)
                        {
                            Monitor.PulseAll(waitLock);
                        }
                    }
                }));
                Monitor.Wait(waitLock);
            }
        }
开发者ID:xmcy0011,项目名称:NanUI,代码行数:49,代码来源:ChromiumBrowser.cs


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