110,538
社区成员
发帖
与我相关
我的任务
分享
this.Label1.InvokeEx(e => e.Text = DateTime.Now);
public static void InvokeEx<T>(this T @this, Action<T> action) where T : Control
{
if (@this.InvokeRequired)
@this.Invoke(action, new object[] { @this });
else
{
if (!@this.IsHandleCreated)
return;
if (@this.IsDisposed)
throw new ObjectDisposedException("@this is disposed.");
action(@this);
}
}
public static IAsyncResult BeginInvokeEx<T>(this T @this, Action<T> action) where T : Control
{
return @this.BeginInvoke((Action)delegate { @this.InvokeEx(action); });
}
public static void EndInvokeEx<T>(this T @this, IAsyncResult result) where T : Control
{
@this.EndInvoke(result);
}
label.Dispatcher.Invoke(() =>{ label.Content = DateTime.Now; });