1- // Copyright (c) .NET Foundation. All rights reserved.
1+ // Copyright (c) .NET Foundation. All rights reserved.
22// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
33
44using System ;
5+ using System . Diagnostics ;
56using System . Runtime . CompilerServices ;
67using System . Threading ;
78using System . Threading . Tasks ;
@@ -12,10 +13,11 @@ public static class TaskExtensions
1213 {
1314 public static async Task < T > TimeoutAfter < T > ( this Task < T > task , TimeSpan timeout ,
1415 [ CallerFilePath ] string filePath = null ,
15- [ CallerLineNumber ] int lineNumber = default ( int ) )
16+ [ CallerLineNumber ] int lineNumber = default )
1617 {
1718 // Don't create a timer if the task is already completed
18- if ( task . IsCompleted )
19+ // or the debugger is attached
20+ if ( task . IsCompleted || Debugger . IsAttached )
1921 {
2022 return await task ;
2123 }
@@ -28,17 +30,17 @@ public static async Task<T> TimeoutAfter<T>(this Task<T> task, TimeSpan timeout,
2830 }
2931 else
3032 {
31- throw new TimeoutException (
32- CreateMessage ( timeout , filePath , lineNumber ) ) ;
33+ throw new TimeoutException ( CreateMessage ( timeout , filePath , lineNumber ) ) ;
3334 }
3435 }
3536
3637 public static async Task TimeoutAfter ( this Task task , TimeSpan timeout ,
3738 [ CallerFilePath ] string filePath = null ,
38- [ CallerLineNumber ] int lineNumber = default ( int ) )
39+ [ CallerLineNumber ] int lineNumber = default )
3940 {
4041 // Don't create a timer if the task is already completed
41- if ( task . IsCompleted )
42+ // or the debugger is attached
43+ if ( task . IsCompleted || Debugger . IsAttached )
4244 {
4345 await task ;
4446 return ;
0 commit comments