这两个是系统自带的委托,
利用这两个现成的委托我们可以省去自定义简单委托的步骤。
Action<T>只有参数没有返回值
Func<T,ResultT>既有参数也有返回值
T代表了你要执行的方法的参数类型。
在2.0中只有Action<T>一种形式,
在3.5中增加了Action以及Action<T1,T2>等最多四个参数,Func<T,ResultT>,Func<T1,T2,ResultT>最多四个参数。
//更新进度条
private void button1_Click( object sender, EventArgs e)
{
Thread t = new Thread(
() => progressBar1.Invoke(
new Action(() =>
{
for ( int i = 0 ; i < 50 ; i ++ )
{
progressBar1.Value = i;
}
}))
);
t.Start();
}
private void button1_Click( object sender, EventArgs e)
{
Thread t = new Thread(
() => progressBar1.Invoke(
new Action(() =>
{
for ( int i = 0 ; i < 50 ; i ++ )
{
progressBar1.Value = i;
}
}))
);
t.Start();
}