Skip to content

Commit 8f5208a

Browse files
committed
Add cancellation token to AzureRMCmdlet
1 parent 8f53efa commit 8f5208a

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/ResourceManager/Version2016_09_01/AzureRMCmdlet.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
using System.Management.Automation;
3131
using System.Net.Http.Headers;
3232
using System.Security.Authentication;
33+
using System.Threading;
3334
using System.Text;
3435

3536
namespace Microsoft.Azure.Commands.ResourceManager.Common
@@ -298,7 +299,7 @@ protected override void InitializeQosEvent()
298299
{
299300
_qosEvent.SubscriptionId = context.Subscription?.Id;
300301
_qosEvent.TenantId = context.Tenant?.Id;
301-
if(context.Account != null && !String.IsNullOrWhiteSpace(context.Account.Id))
302+
if (context.Account != null && !String.IsNullOrWhiteSpace(context.Account.Id))
302303
{
303304
_qosEvent.Uid = MetricHelper.GenerateSha256HashString(context.Account.Id.ToString());
304305
}
@@ -546,5 +547,24 @@ private void EnqueueDebugSender(object sender, StreamEventArgs args)
546547
{
547548
DebugMessages.Enqueue(args.Message);
548549
}
550+
551+
private CancellationTokenSource _cancellationtokensource = null;
552+
protected CancellationTokenSource CancelTokenSource
553+
{
554+
get
555+
{
556+
if (_cancellationtokensource == null)
557+
{
558+
_cancellationtokensource = new CancellationTokenSource();
559+
}
560+
return _cancellationtokensource;
561+
}
562+
}
563+
564+
protected override void StopProcessing()
565+
{
566+
CancelTokenSource?.Cancel();
567+
base.StopProcessing();
568+
}
549569
}
550570
}

0 commit comments

Comments
 (0)