From 8f5208ad84e9811652a1529f9a5530e950478b9e Mon Sep 17 00:00:00 2001 From: Lei Jin Date: Mon, 10 May 2021 13:16:03 +0800 Subject: [PATCH] Add cancellation token to AzureRMCmdlet --- .../Version2016_09_01/AzureRMCmdlet.cs | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/ResourceManager/Version2016_09_01/AzureRMCmdlet.cs b/src/ResourceManager/Version2016_09_01/AzureRMCmdlet.cs index 1ee276071d..d2fbd6bc9f 100644 --- a/src/ResourceManager/Version2016_09_01/AzureRMCmdlet.cs +++ b/src/ResourceManager/Version2016_09_01/AzureRMCmdlet.cs @@ -30,6 +30,7 @@ using System.Management.Automation; using System.Net.Http.Headers; using System.Security.Authentication; +using System.Threading; using System.Text; namespace Microsoft.Azure.Commands.ResourceManager.Common @@ -298,7 +299,7 @@ protected override void InitializeQosEvent() { _qosEvent.SubscriptionId = context.Subscription?.Id; _qosEvent.TenantId = context.Tenant?.Id; - if(context.Account != null && !String.IsNullOrWhiteSpace(context.Account.Id)) + if (context.Account != null && !String.IsNullOrWhiteSpace(context.Account.Id)) { _qosEvent.Uid = MetricHelper.GenerateSha256HashString(context.Account.Id.ToString()); } @@ -546,5 +547,24 @@ private void EnqueueDebugSender(object sender, StreamEventArgs args) { DebugMessages.Enqueue(args.Message); } + + private CancellationTokenSource _cancellationtokensource = null; + protected CancellationTokenSource CancelTokenSource + { + get + { + if (_cancellationtokensource == null) + { + _cancellationtokensource = new CancellationTokenSource(); + } + return _cancellationtokensource; + } + } + + protected override void StopProcessing() + { + CancelTokenSource?.Cancel(); + base.StopProcessing(); + } } }