4
我有我在WinForms中使用的这种扩展方法,但想知道如何我可以用WPF实现相同的概念。通用WPF多线程访问控件
public static void SafeThreadAction<T>(this T control, Action<T> call)
where T : System.Windows.Forms.Control
{
if(control.InvokeRequired)
control.Invoke(call, control);
else
call(control);
}
加布,我不认为你需要的第二个参数中进行的调用(),因为你已经调用控件的调度。添加呼叫优先权参数也可能值得考虑。 – Alan 2011-04-25 08:42:11
@Alan:第二个参数是必需的,因为'call'是一个'Action'而不仅仅是一个'Action'。 –
Gabe
2011-04-25 08:47:24
哦,你是对的,傻我:) – Alan 2011-04-25 08:53:55