Dispatcher BeginInvoke Syntax

后端 未结 3 1661
灰色年华
灰色年华 2020-12-04 16:23

I have been trying to follow some WCF Data Services examples and have the following code:

private void OnSaveCompleted(IAsyncResult result)
    {
        Disp         


        
3条回答
  •  庸人自扰
    2020-12-04 17:14

    The problem is that the compiler doesn't know what kind of delegate you're trying to convert the lambda expression to. You can fix that either with a cast, or a separate variable:

    private void OnSaveCompleted(IAsyncResult result)
    {        
        Dispatcher.BeginInvoke((Action) (() =>
        {
            context.EndSaveChanges(result);
        }));
    }
    

    or

    private void OnSaveCompleted(IAsyncResult result)
    {
        Action action = () =>
        {
            context.EndSaveChanges(result);
        };
        Dispatcher.BeginInvoke(action);
    }
    

提交回复
热议问题