当前位置: 动力学知识库 > 问答 > 编程问答 >

c# - Cannot convert lambda expression to type 'System.Delegate' because it is not a delegate type in wpf

问题描述:

public void loadtemplist(DataTable dt)

{

this.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle,

(Delegate) (() => this.loadtemplist1(dt)) //error

);

}

and

public void loadtemplist1(DataTable dt)

{

-----

-----

}

the above code throws Cannot convert lambda expression to type 'System.Delegate' because it is not a delegate type

网友答案:

You can't convert an anonymous method straight to a System.Delegate - you need to wrap it in an Action first.

Try this instead:

public void loadtemplist(DataTable dt)
{
  this.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle,

      new Action(() => { this.loadtemplist1(dt); } )
      );
}
网友答案:

you should do

this.Dispatcher.BeginInvoke(DispatcherPriority.ApplicationIdle, 
                            new Action(() => this.loadtemplist1(dt)) );

see demo: https://dotnetfiddle.net/nz9xxD

分享给朋友:
您可能感兴趣的文章:
随机阅读: