What are the differences between this two methods that seems to do the same thing? Can it be done even with async/await?
public Task<int> TaskMaxAsync1 ( Task<int>[] my_ints ) { return Task.WhenAll( my_ints ) .ContinueWith ( x => x.Result.Where ( i => i%2 != 0 ).Max( ) ) ; } public Task<int> TaskMaxAsync2 ( Task<int>[] my_ints ) { var numbers = Task.WhenAll( my_ints ).Result ; return Task.FromResult( numbers.Where( i => i%2 != 0 ).Max( ) ) ; }
.Resultis prone to deadlocking - stackoverflow.com/questions/17248680/….Resultoutside ofContinueWith(ie. the second one) is prone to deadlocking. The only place it is safe to read.Resultis from a task that is guaranteed to have completed. Reading.Resultfrom a task that has not yet completed may deadlock.