110,534
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Threading;
namespace Model
{
public static class ControlExtended
{
public delegate void InvokeHandler();
/// <summary>
/// 线程操作Invoke
/// </summary>
/// <param name="control"></param>
/// <param name="handler"></param>
public static void UIInvoke(this Control control, InvokeHandler handler)
{
if (control.InvokeRequired)
{
control.Invoke(handler);
}
else
{
handler();
}
}
}
}
//调用
private void button3_Click(object sender, EventArgs e)
{
Thread tdAdd = new Thread(function);
tdAdd.Start();
}
public void function()
{
this.UIInvoke(() =>
{
//执行代码
});
}