我想在 WPF 应用程序的主线程上执行此代码并收到错误我无法弄清楚出了什么问题:
private void AddLog(string logItem)
{
this.Dispatcher.BeginInvoke(
delegate()
{
this.Log.Add(new KeyValuePair<string, string>(DateTime.Now.ToLongTimeString(), logItem));
});
}
最佳答案
您也可以使用MethodInvoker为了这:
private void AddLog(string logItem)
{
this.Dispatcher.BeginInvoke((MethodInvoker) delegate
{
this.Log.Add(new KeyValuePair<string, string>(DateTime.Now.ToLongTimeString(), logItem));
});
}
关于c# - 无法将匿名方法转换为类型 'System.Delegate',因为它不是委托(delegate)类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15935867/