@@ -8,6 +8,7 @@ internal static class TaskAndFactoryExtensions
88 {
99 #region Task Extensions
1010
11+ // TODO: Not used, is this used in Deploy or something?
1112 static void SetCompletionSource < TResult > ( TaskCompletionSource < TResult > completionSource , Task task )
1213 {
1314 if ( task . IsFaulted )
@@ -16,6 +17,7 @@ static void SetCompletionSource<TResult>(TaskCompletionSource<TResult> completio
1617 completionSource . SetResult ( default ( TResult ) ) ;
1718 }
1819
20+ // TODO: Not used, is this used in Deploy or something?
1921 static void SetCompletionSource < TResult > ( TaskCompletionSource < TResult > completionSource , Task < TResult > task )
2022 {
2123 if ( task . IsFaulted )
@@ -24,17 +26,33 @@ static void SetCompletionSource<TResult>(TaskCompletionSource<TResult> completio
2426 completionSource . SetResult ( task . Result ) ;
2527 }
2628
29+ // TODO: Not used, is this used in Deploy or something?
2730 public static Task ContinueWithTask ( this Task task , Func < Task , Task > continuation )
2831 {
2932 var completionSource = new TaskCompletionSource < object > ( ) ;
30- task . ContinueWith ( atask => continuation ( atask ) . ContinueWith ( atask2 => SetCompletionSource ( completionSource , atask2 ) ) ) ;
33+ task . ContinueWith ( atask => continuation ( atask ) . ContinueWith (
34+ atask2 => SetCompletionSource ( completionSource , atask2 ) ,
35+ // Must explicitly specify this, see https://blog.stephencleary.com/2013/10/continuewith-is-dangerous-too.html
36+ TaskScheduler . Default ) ,
37+ // Must explicitly specify this, see https://blog.stephencleary.com/2013/10/continuewith-is-dangerous-too.html
38+ TaskScheduler . Default ) ;
3139 return completionSource . Task ;
3240 }
3341
42+ // TODO: Not used, is this used in Deploy or something?
3443 public static Task ContinueWithTask ( this Task task , Func < Task , Task > continuation , CancellationToken token )
3544 {
3645 var completionSource = new TaskCompletionSource < object > ( ) ;
37- task . ContinueWith ( atask => continuation ( atask ) . ContinueWith ( atask2 => SetCompletionSource ( completionSource , atask2 ) , token ) , token ) ;
46+ task . ContinueWith ( atask => continuation ( atask ) . ContinueWith (
47+ atask2 => SetCompletionSource ( completionSource , atask2 ) ,
48+ token ,
49+ TaskContinuationOptions . None ,
50+ // Must explicitly specify this, see https://blog.stephencleary.com/2013/10/continuewith-is-dangerous-too.html
51+ TaskScheduler . Default ) ,
52+ token ,
53+ TaskContinuationOptions . None ,
54+ // Must explicitly specify this, see https://blog.stephencleary.com/2013/10/continuewith-is-dangerous-too.html
55+ TaskScheduler . Default ) ;
3856 return completionSource . Task ;
3957 }
4058
0 commit comments