I have a method that lasts a long time: it calls the database and performs certain calculations synchronously:
public static MyResult MyMethod(int param1, int param2) {
I want to write a wrapper for it so that I can use it from my WinForms interface with the keyword 'wait'. To do this, I create another method, MyResultAsync. I have a choice of how to write it:
// option 1 public async static Task<MyResult> MyResultAsync(int param1, int param2) { return await TaskEx.Run(() => MyMethod(param1, param2)); } // option 2 public static Task<MyResult> MyResultAsync(int param1, int param2) { return TaskEx.Run(() => MyMethod(param1, param2)); }
So which option is preferable and why? As you can see, the only difference is the presence / absence of the keywords "async" and "wait".
Thanks!
source share