读书人

一种奇怪的写法,求解答解决方法

发布时间: 2011-12-30 23:30:45 作者: rapoo

一种奇怪的写法,求解答
private void m_OnOccurErr(int errCode)
{
this.SafeInvoke(() =>
{
switch (errCode)
{
case 1:
textBox4.Text = "等待超时错误!";
break;
case 2:
textBox4.Text = "获取状态错误!";
break;
default:
break;
}

});
}




public delegate void InvokeHandler();

public static void SafeInvoke(this Control control, InvokeHandler handler)
{
if (control.InvokeRequired)
{
control.Invoke(handler);
}
else
{
handler();
}
}

[解决办法]
那里奇怪啊,挺正常滴

C# code
public delegate void InvokeHandler();  public static void SafeInvoke(this Control control, InvokeHandler handler)//此处是扩展方法,对Control对象扩展一个safeInvoke方法,InvokeHandler则是委托  {  if (control.InvokeRequired)  {  control.Invoke(handler);  }  else  {  handler();  }  } 

读书人网 >.NET

热点推荐