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


C# Control.Invoke方法代码示例

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


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

示例1: SetControlPropertyThreadSafe

 public static void SetControlPropertyThreadSafe(Control control, string propertyName, object propertyValue)
 {
     if (control == null)
     {
         throw new ArgumentNullException("control");
     }
     if (control.InvokeRequired)
     {
         if (control.IsHandleCreated)
         {
             try
             {
                 control.Invoke(new SetControlPropertyThreadSafeDelegate(SetControlPropertyThreadSafe), new object[] { control, propertyName, propertyValue });
             }
             catch { }
         }
     }
     else
     {
         if (!control.IsDisposed)
         {
             try
             {
                 control.GetType().InvokeMember(propertyName, BindingFlags.SetProperty, null, control, new object[] { propertyValue });
             }
             catch { }
         }
     }
 }
开发者ID:ChromeFoundry,项目名称:NAS4FreeConsole,代码行数:29,代码来源:Console.cs

示例2: SetControlPropertyThreadSafe

 public static void SetControlPropertyThreadSafe(Control control, string propertyName, object propertyValue)
 {
     if (control.InvokeRequired) control.Invoke(new SetControlPropertyThreadSafeDelegate(SetControlPropertyThreadSafe),
          new object[] { control, propertyName, propertyValue });
     else control.GetType().InvokeMember(propertyName, System.Reflection.BindingFlags.SetProperty, null, control,
         new object[] { propertyValue });
 }
开发者ID:catterpiler74,项目名称:TempFromMaisToMagnesius,代码行数:7,代码来源:UserControl1.cs

示例3: add_text

 public static void add_text(Control c, object s)
 {
     if (c.InvokeRequired)
         c.Invoke(new Action<Control, object>(add_text), new object[] { c, s });
     else
         c.Text += s.ToString();
 }
开发者ID:HowieXue,项目名称:Hospital_projs,代码行数:7,代码来源:Helper.cs

示例4: Get

        public static object Get(Control control, object noncontrol, string propertyName)
        {
            if (control != null && !string.IsNullOrEmpty(propertyName))
                if (control.InvokeRequired)
                    return control.Invoke(new PropertyGetInvoker(Get),
                        control,
                        noncontrol,
                        propertyName
                        );
                else
                {
                    PropertyInfo pi = GetPropertyInfo(control, noncontrol, propertyName);
                    object invokee = (noncontrol == null) ? control : noncontrol;

                    if (pi != null)
                        if (pi.CanRead)
                            return pi.GetValue(invokee, null);
                        else
                            throw new Exception(
                                string.Format(
                                "{0}.{1} is a write-only property.",
                                invokee.GetType().ToString(),
                                propertyName
                                ));

                    return null;
                }
            else
                throw new ArgumentNullException("Invalid argument.");
        }
开发者ID:neozhu,项目名称:wmsrf-winceclient,代码行数:30,代码来源:InvokeHelper.cs

示例5: SetText

 public static void SetText(Control control, string text)
 {
     if (control.InvokeRequired)
         control.Invoke(new SetTextDelegate(SetText), control, text);
     else
         control.Text = text;
 }
开发者ID:greeduomacro,项目名称:phoenix,代码行数:7,代码来源:Safe.cs

示例6: SetEnabled

 public static void SetEnabled(Control control, bool value)
 {
     if (control.InvokeRequired)
         control.Invoke(new SetEnabledDelegate(SetEnabled), control, value);
     else
         control.Enabled = value;
 }
开发者ID:greeduomacro,项目名称:phoenix,代码行数:7,代码来源:Safe.cs

示例7: ResetText

 public static void ResetText(Control control)
 {
     if (control.InvokeRequired)
         control.Invoke(new ResetTextDelegate(ResetText), control);
     else
         control.ResetText();
 }
开发者ID:greeduomacro,项目名称:phoenix,代码行数:7,代码来源:Safe.cs

示例8: Hide

 public static void Hide(Control control)
 {
     if (control.InvokeRequired)
         control.Invoke(new ShowHideDelegate(Hide), control);
     else
         control.Hide();
 }
开发者ID:greeduomacro,项目名称:phoenix,代码行数:7,代码来源:Safe.cs

示例9: InvokeOnUiThread

 public void InvokeOnUiThread(Control control, Action<Control> action)
 {
     if(control.InvokeRequired)
     {
         control.Invoke(action);
     }
 }
开发者ID:HNeukermans,项目名称:Hallo,代码行数:7,代码来源:FormHelper.cs

示例10: InvokeIfRequired

 public static void InvokeIfRequired(Control c, VoidDelegate d)
 {
     if (c.InvokeRequired)
         c.Invoke(d);
     else
         d.Invoke();
 }
开发者ID:JesusFreke,项目名称:didjimp,代码行数:7,代码来源:InvokeUtil.cs

示例11: GetPropertyValue

        /// <summary>
        /// Get a property value on the control thread-safely.
        /// </summary>
        /// <param name="control">Control on which to GET the property value</param>
        /// <param name="propertyName">Property name</param>
        /// <return>Property value</return>
        public static object GetPropertyValue(Control control, string propertyName)
        {
            if (control != null && !string.IsNullOrEmpty(propertyName))
            {
                if (control.InvokeRequired)
                {
                    return control.Invoke(new PropertyGetInvoker(GetPropertyValue),
                                          control, propertyName);
                }
                else
                {
                    PropertyInfo propertyInfo = GetProperty(control, propertyName);
                    if (propertyInfo != null)
                    {
                        if (propertyInfo.CanRead)
                        {
                            return propertyInfo.GetValue(control, null);
                        }
                        else
                        {
                            throw new Exception(control.GetType().ToString() + "." + propertyName +
                                                " is write-only property.");
                        }
                    }

                    return null;
                }
            }
            else
            {
                throw new ArgumentNullException();
            }
        }
开发者ID:khaha2210,项目名称:CodeNewTeam,代码行数:39,代码来源:SafeInvokeUtils.cs

示例12: GetControlOwnerThread

 private Thread GetControlOwnerThread(Control ctrl)
 {
     if (ctrl.InvokeRequired)
         return (Thread)ctrl.Invoke(new Func<Thread>(() => GetControlOwnerThread(ctrl)));
     else
         return System.Threading.Thread.CurrentThread;
 }
开发者ID:gitter-badger,项目名称:reko,代码行数:7,代码来源:DecompilerUiService.cs

示例13: InvokeIfNecessary

 public static void InvokeIfNecessary(Control control, MethodInvoker action)
 {
     if (control.InvokeRequired)
         control.Invoke(action);
     else
         action();
 }
开发者ID:tmeckel,项目名称:PRFCreator,代码行数:7,代码来源:Utility.cs

示例14: EnableControl

 private void EnableControl(Control control)
 {
     control.Invoke(new Action(() =>
     {
         control.Enabled = true;
     }));
 }
开发者ID:pseudomuto,项目名称:sudoku-solver,代码行数:7,代码来源:SolverUI.cs

示例15: ControlInvokeRequired

        /// <summary>
        /// Helper method to determin if invoke required, if so will rerun method on correct thread.
        /// if not do nothing. From: http://stackoverflow.com/a/26506378/457880
        /// </summary>
        /// <param name="c">Control that might require invoking</param>
        /// <param name="a">action to preform on control thread if so.</param>
        /// <returns>true if invoke required</returns>
        public bool ControlInvokeRequired(Control c, Action a)
        {
            if (c.InvokeRequired) c.Invoke(new MethodInvoker(delegate { a(); }));
            else return false;

            return true;
        }
开发者ID:robeat101,项目名称:beakn,代码行数:14,代码来源:Beakn.cs


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