-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDebuggerExtensions.cs
32 lines (28 loc) · 1.05 KB
/
DebuggerExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using System.Diagnostics;
using System.Threading.Tasks;
namespace MockLambdaRuntime
{
internal static class DebuggerExtensions
{
/// <summary>
/// Tries to wait for the debugger to attach by inspecting <see cref="Debugger.IsAttached"/> property in a loop.
/// </summary>
/// <param name="queryInterval"><see cref="TimeSpan"/> representing the frequency of inspection.</param>
/// <param name="timeout"><see cref="TimeSpan"/> representing the timeout for the operation.</param>
/// <returns><c>True</c> if debugger was attached, false if timeout occured.</returns>
public static bool TryWaitForAttaching(TimeSpan queryInterval, TimeSpan timeout)
{
var stopwatch = Stopwatch.StartNew();
while (!Debugger.IsAttached)
{
if (stopwatch.Elapsed > timeout)
{
return false;
}
Task.Delay(queryInterval).Wait();
}
return true;
}
}
}