From 9b1c78a3935a56ecebb142b023384943506e036f Mon Sep 17 00:00:00 2001 From: Andrew Arnott Date: Wed, 26 Dec 2012 10:11:56 -0800 Subject: [PATCH] Fixes build break in .NET 3.5 builds. --- .../Messaging/MessagingUtilities.cs | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs b/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs index 388157a11b..e859162980 100644 --- a/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs +++ b/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs @@ -2026,17 +2026,22 @@ private static class ThreadSafeRandom { /// /// A thread-local instance of /// - private static readonly ThreadLocal threadRandom = new ThreadLocal(delegate { - lock (threadRandomInitializer) { - return new Random(threadRandomInitializer.Next()); - } - }); + [ThreadStatic] + private static Random threadRandom; /// /// Gets a random number generator for use on the current thread only. /// public static Random RandomNumberGenerator { - get { return threadRandom.Value; } + get { + if (threadRandom == null) { + lock (threadRandomInitializer) { + threadRandom = new Random(threadRandomInitializer.Next()); + } + } + + return threadRandom; + } } }