在WPF中没有了WinForm下的InvokeRequired属性。
在WPF界面中如果有子线程操作,可以使用下面方法:
private
TextBlock txtBlockInfo;
private
delegate void ChangeText(string txtInfo);
private
void WriteInfo(string strInfo)
{
if
(txtBlockInfo.Dispatcher.CheckAccess())
{
txtBlockInfo.Text
= strInfo;
}
else
{
txtBlockInfo.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal,
new ChangeText(WriteInfo), strInfo);
}
}
使用Dispatcher.CheckAccess()实现线程间交互。