diff options
Diffstat (limited to 'src/DotNetOpenAuth.Core/Messaging')
-rw-r--r-- | src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs b/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs index 388157a..e859162 100644 --- a/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs +++ b/src/DotNetOpenAuth.Core/Messaging/MessagingUtilities.cs @@ -2026,17 +2026,22 @@ namespace DotNetOpenAuth.Messaging { /// <summary> /// A thread-local instance of <see cref="Random"/> /// </summary> - private static readonly ThreadLocal<Random> threadRandom = new ThreadLocal<Random>(delegate { - lock (threadRandomInitializer) { - return new Random(threadRandomInitializer.Next()); - } - }); + [ThreadStatic] + private static Random threadRandom; /// <summary> /// Gets a random number generator for use on the current thread only. /// </summary> public static Random RandomNumberGenerator { - get { return threadRandom.Value; } + get { + if (threadRandom == null) { + lock (threadRandomInitializer) { + threadRandom = new Random(threadRandomInitializer.Next()); + } + } + + return threadRandom; + } } } |