c#: Lambda expression is not a delegate type

No comments
I was changing some code from Silverlight to WPF and ran into this error:
        Cannot convert lambda expression to type 'System.Windows.Threading.DispatcherPriority' because it is not a delegate type
The code was something like this
gui.BeginInvoke(
        ()=>
        {
         Orders = new ObservableCollection<Order>(x);
        }
        ,null
);
The problem is described in detail here:
The article suggests a couple of ways around this, but the best solution in my opinion is found in the comments:
Cast the lambda to an Action explicitly.
It's fast to do, easy and intuitive:
        gui.BeginInvoke(
         (Action)(()=>
             {
                         Orders = new ObservableCollection<Order>(x);
                })
                 ,null
        );
This compiles and runs fine.
Happy holidays
/Henri

No comments :

Post a Comment