c# - .NET async/await: in this case should I return something? -


in case this, task return instantly because of conditions:

public async task test(list<int> testlist) {     if (testlist.count() == 0)         return;      //     await uploadlistasync(testlist); } 

is correct return;, should use task.fromresult(false);, or there more correct way?

when you're using async, can't return task explicitly (see edit) - return value has been boxed compiler return value of task. thus, async methods should behave other methods , return if need bail out of logic early.

edit: 1 time can return task during async if return type task<task..., still returning inner task, not outer, since compiler has done same wrapping. should rare use case opposed await-ing chain of tasks


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -