Dispatcher BeginInvoke Syntax

后端 未结 3 1664
灰色年华
灰色年华 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:06

    Answer by Jon Skeet is very good but there are other possibilities. I prefer "begin invoke new action" which is easy to read and to remember for me.

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

    or

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

    or

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

提交回复
热议问题