task-parallel-library

Why does assigning a Task then awaiting it allow to run in parallel

怎甘沉沦 提交于 2020-11-29 09:17:07
问题 I've was playing around with async and I've happened across some behaviour I've not noticed before, if this is a duplicate please let me know, but my google-fu has failed me, mostly because I can't think of decent terms to search: Given a simple async method that does some parameterized work: async Task<String> Foo(int i) { await Task.Delay(i); return i.ToString(); } And a calling method to invoke it in different contexts and bundle the result: async Task<Object> Bar() { var one = Foo(3000);

Why does assigning a Task then awaiting it allow to run in parallel

假装没事ソ 提交于 2020-11-29 09:17:05
问题 I've was playing around with async and I've happened across some behaviour I've not noticed before, if this is a duplicate please let me know, but my google-fu has failed me, mostly because I can't think of decent terms to search: Given a simple async method that does some parameterized work: async Task<String> Foo(int i) { await Task.Delay(i); return i.ToString(); } And a calling method to invoke it in different contexts and bundle the result: async Task<Object> Bar() { var one = Foo(3000);