From 4d0944b037492f6c641b9cf8cf7d725f30d76620 Mon Sep 17 00:00:00 2001 From: Andrii Bratanin Date: Wed, 24 May 2017 04:14:52 +0300 Subject: [PATCH] Mitigate possible race condition in MessageHandler1 (#3402) MSDN description of DelegatingHandler Class says: "Any instance members are not guaranteed to be thread safe" https://msdn.microsoft.com/en-us/library/system.net.http.delegatinghandler(v=vs.118).aspx --- .../advanced/httpclient-message-handlers/samples/sample2.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/aspnet/web-api/overview/advanced/httpclient-message-handlers/samples/sample2.cs b/aspnet/web-api/overview/advanced/httpclient-message-handlers/samples/sample2.cs index 5f4c540877..8899a7735d 100644 --- a/aspnet/web-api/overview/advanced/httpclient-message-handlers/samples/sample2.cs +++ b/aspnet/web-api/overview/advanced/httpclient-message-handlers/samples/sample2.cs @@ -5,8 +5,8 @@ class MessageHandler1 : DelegatingHandler protected override Task SendAsync( HttpRequestMessage request, System.Threading.CancellationToken cancellationToken) { - _count++; + System.Threading.Interlocked.Increment(ref _count); request.Headers.Add("X-Custom-Header", _count.ToString()); return base.SendAsync(request, cancellationToken); } -} \ No newline at end of file +}