Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
// Copyright (c) .NET Foundation. All rights reserved.
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.

using System;
using System.Diagnostics;
using System.Runtime.CompilerServices;
using System.Threading;
using System.Threading.Tasks;
Expand All @@ -12,10 +13,11 @@ public static class TaskExtensions
{
public static async Task<T> TimeoutAfter<T>(this Task<T> task, TimeSpan timeout,
[CallerFilePath] string filePath = null,
[CallerLineNumber] int lineNumber = default(int))
[CallerLineNumber] int lineNumber = default)
{
// Don't create a timer if the task is already completed
if (task.IsCompleted)
// or the debugger is attached
if (task.IsCompleted || Debugger.IsAttached)
{
return await task;
}
Expand All @@ -28,17 +30,17 @@ public static async Task<T> TimeoutAfter<T>(this Task<T> task, TimeSpan timeout,
}
else
{
throw new TimeoutException(
CreateMessage(timeout, filePath, lineNumber));
throw new TimeoutException(CreateMessage(timeout, filePath, lineNumber));
}
}

public static async Task TimeoutAfter(this Task task, TimeSpan timeout,
[CallerFilePath] string filePath = null,
[CallerLineNumber] int lineNumber = default(int))
[CallerLineNumber] int lineNumber = default)
{
// Don't create a timer if the task is already completed
if (task.IsCompleted)
// or the debugger is attached
if (task.IsCompleted || Debugger.IsAttached)
{
await task;
return;
Expand Down