From 1c6a9da9c816ceba6b1caaadcbd660c79cbf82f9 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Wed, 22 May 2024 15:03:55 -0400 Subject: [PATCH] Remove use of "this" in ProcessingQueue --- CHANGELIST.md | 1 + MPF.Core/Data/ProcessingQueue.cs | 24 ++++++++++++------------ MPF.Test/UI/AllowedSpeedsTest.cs | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/CHANGELIST.md b/CHANGELIST.md index 63e8005c..101eb531 100644 --- a/CHANGELIST.md +++ b/CHANGELIST.md @@ -51,6 +51,7 @@ - Reduce accessors for DumpEnvironment - Better handle interface constants - Make StringEventArgs internally consistent +- Remove use of "this" in ProcessingQueue ### 3.1.9a (2024-05-21) diff --git a/MPF.Core/Data/ProcessingQueue.cs b/MPF.Core/Data/ProcessingQueue.cs index 1a50dbd5..816f8201 100644 --- a/MPF.Core/Data/ProcessingQueue.cs +++ b/MPF.Core/Data/ProcessingQueue.cs @@ -33,25 +33,25 @@ namespace MPF.Core.Data public ProcessingQueue(Action customProcessing) { #if NET20 || NET35 - this.InternalQueue = new Queue(); + InternalQueue = new Queue(); #else - this.InternalQueue = new ConcurrentQueue(); + InternalQueue = new ConcurrentQueue(); #endif - this.CustomProcessing = customProcessing; - this.TokenSource = new CancellationTokenSource(); + CustomProcessing = customProcessing; + TokenSource = new CancellationTokenSource(); #if NET20 || NET35 Task.Run(() => ProcessQueue()); #elif NET40 Task.Factory.StartNew(() => ProcessQueue()); #else - Task.Run(() => ProcessQueue(), this.TokenSource.Token); + Task.Run(() => ProcessQueue(), TokenSource.Token); #endif } /// /// Dispose the current instance /// - public void Dispose() => this.TokenSource.Cancel(); + public void Dispose() => TokenSource.Cancel(); /// /// Enqueue a new item for processing @@ -60,8 +60,8 @@ namespace MPF.Core.Data public void Enqueue(T? item) { // Only accept new data when not cancelled - if (item != null && !this.TokenSource.IsCancellationRequested) - this.InternalQueue.Enqueue(item); + if (item != null && !TokenSource.IsCancellationRequested) + InternalQueue.Enqueue(item); } /// @@ -78,7 +78,7 @@ namespace MPF.Core.Data if (InternalQueue.IsEmpty) #endif { - if (this.TokenSource.IsCancellationRequested) + if (TokenSource.IsCancellationRequested) break; Thread.Sleep(1); @@ -87,14 +87,14 @@ namespace MPF.Core.Data #if NET20 || NET35 // Get the next item from the queue and invoke the lambda, if possible - this.CustomProcessing?.Invoke(this.InternalQueue.Dequeue()); + CustomProcessing?.Invoke(InternalQueue.Dequeue()); #else // Get the next item from the queue - if (!this.InternalQueue.TryDequeue(out var nextItem)) + if (!InternalQueue.TryDequeue(out var nextItem)) continue; // Invoke the lambda, if possible - this.CustomProcessing?.Invoke(nextItem); + CustomProcessing?.Invoke(nextItem); #endif } } diff --git a/MPF.Test/UI/AllowedSpeedsTest.cs b/MPF.Test/UI/AllowedSpeedsTest.cs index c1a196d8..fed36fb2 100644 --- a/MPF.Test/UI/AllowedSpeedsTest.cs +++ b/MPF.Test/UI/AllowedSpeedsTest.cs @@ -1,4 +1,4 @@ -using MPF.Core.Data; +using MPF.Core.UI; using SabreTools.RedumpLib.Data; using Xunit;