1、跨线程访问控件委托和类的定义
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
using System;using System.Windows.Forms;namespace ahwildlife.Utils{ ////// 跨线程访问控件的委托 /// public delegate void InvokeDelegate(); ////// 跨线程访问控件类 /// public class InvokeUtil { ////// 跨线程访问控件 /// /// Form对象 /// 委托 public static void Invoke(Control ctrl, InvokeDelegate de) { if (ctrl.IsHandleCreated) { ctrl.BeginInvoke(de); } } }}
2、如何使用
在Form1.cs文件的线程方法中:
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
![](https://images.cnblogs.com/OutliningIndicators/ExpandedBlockStart.gif)
InvokeDelegate invokeDelegate = delegate() { button4.Enabled = false; button5.Enabled = false; button6.Enabled = false; button7.Enabled = false; button8.Enabled = false; }; InvokeUtil.Invoke(this, invokeDelegate);