我得到了以下窗体来:
if (richTextBoxReceive.InvokeRequired)
{
richTextBoxReceive.Invoke(new MethodInvoker(()=>
richTextBoxReceive.AppendText(string.Format("{0}\n\r", msg))));
}
else
{
richTextBoxReceive.AppendText(string.Format("{0}\n\r", msg));
}
i am using this code in WPF aplication and when i replace whit
if (richTextBoxReceive.Dispatcher.CheckAccess())
{
richTextBoxReceive.Dispatcher.Invoke(new MethodInvoker(()=>
richTextBoxReceive.AppendText(string.Format("{0}\n\r", msg))));
}
else
{
richTextBoxReceive.AppendText(string.Format("{0}\n\r", msg));
}
我得到3个错误:
1)错误:WpfApplication1.MethodInvoker不包含带有1个参数的构造函数
2)错误:参数1:无法从'WpfApplication1.MethodInvoker转换为System.Delegate
3)错误:System.Windows.Threading.Dispatcher.Invoke(System.Delegate,params object [])的最佳重载方法匹配有一些无效的参数
我是WPF的新手...我希望我没有提出任何愚蠢的问题,如果你有解决方案我的问题请求帮助我 非常感谢!
答案 0 :(得分:3)
richTextBoxReceive.Dispatcher.Invoke((Action)(()=> ...));