Skip to content

Commit 6fe2350

Browse files
committed
Add timeout to AI flush
1 parent bb69777 commit 6fe2350

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/Common/Commands.Common/MetricHelper.cs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ namespace Microsoft.WindowsAzure.Commands.Common
1414
{
1515
public static class MetricHelper
1616
{
17+
private const int FlushTimeoutInMilli = 5000;
1718
private static readonly TelemetryClient TelemetryClient;
1819

1920
static MetricHelper()
@@ -94,13 +95,10 @@ public static void FlushMetric(bool waitForMetricSending)
9495
return;
9596
}
9697

98+
var flushTask = Task.Run(() => FlushAi());
9799
if (waitForMetricSending)
98100
{
99-
FlushAi();
100-
}
101-
else
102-
{
103-
Task.Run(() => FlushAi());
101+
Task.WaitAll(new[] { flushTask }, FlushTimeoutInMilli);
104102
}
105103
}
106104

0 commit comments

Comments
 (0)