How to call any method asynchronously in c#

后端 未结 5 1692
予麋鹿
予麋鹿 2020-12-07 17:17

Could someone please show me a small snippet of code which demonstrates how to call a method asynchronously in c#?

5条回答
  •  遥遥无期
    2020-12-07 18:02

    Here's a way to do it:

    // The method to call
    void Foo()
    {
    }
    
    
    Action action = Foo;
    action.BeginInvoke(ar => action.EndInvoke(ar), null);
    

    Of course you need to replace Action by another type of delegate if the method has a different signature

提交回复
热议问题