How to call any method asynchronously in c#

后端 未结 5 1689
予麋鹿
予麋鹿 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 17:38

    Starting with .Net 4.5 you can use Task.Run to simply start an action:

    void Foo(string args){}
    ...
    Task.Run(() => Foo("bar"));
    

    Task.Run vs Task.Factory.StartNew

提交回复
热议问题