Cannot convert anonymous method to type 'System.Delegate' because it is not a delegate type

后端 未结 2 990
野的像风
野的像风 2021-02-14 02:55

I want to execute this code on main thread in WPF app and getting error I can\'t figure out what is wrong:

private void AddLog(string logItem)
        {

                


        
2条回答
  •  既然无缘
    2021-02-14 03:39

    You can also use MethodInvoker for this:

    private void AddLog(string logItem)
            {
                this.Dispatcher.BeginInvoke((MethodInvoker) delegate
                {
                    this.Log.Add(new KeyValuePair(DateTime.Now.ToLongTimeString(), logItem));
                });
            }
    

提交回复
热议问题