diff --git a/Canvas.Core/Canvas.Core.csproj b/Canvas.Core/Canvas.Core.csproj index 4b3039f..ede6419 100644 --- a/Canvas.Core/Canvas.Core.csproj +++ b/Canvas.Core/Canvas.Core.csproj @@ -5,7 +5,7 @@ disable disable True - 1.9.8 + 1.9.9 Internal package used in Canvas.Views.Web artemiusgreat indemos.com diff --git a/Canvas.Core/Services/ScheduleService.cs b/Canvas.Core/Services/ScheduleService.cs index f1ea7bd..c27cbce 100644 --- a/Canvas.Core/Services/ScheduleService.cs +++ b/Canvas.Core/Services/ScheduleService.cs @@ -7,29 +7,18 @@ namespace Canvas.Core.Services { public class ScheduleService : IDisposable { - protected virtual Task Consumer { get; set; } - protected virtual BlockingCollection<(Action, TaskCompletionSource)> Queue { get; set; } protected virtual CancellationTokenSource Cancellation { get; set; } + protected virtual BlockingCollection<(Action, TaskCompletionSource)> Queue { get; set; } /// - /// Dispose + /// Constructor /// - public virtual void Dispose() + public ScheduleService() { - Queue?.Dispose(); - Cancellation?.Cancel(); - } + Queue = new(); + Cancellation = new CancellationTokenSource(); - /// - /// Schedule - /// - /// - /// - public virtual Task Schedule(Action action) - { - Queue ??= new(); - Cancellation ??= new CancellationTokenSource(); - Consumer ??= Task.Factory.StartNew(() => + Task.Factory.StartNew(() => { foreach (var (o, com) in Queue.GetConsumingEnumerable()) { @@ -39,15 +28,28 @@ public virtual Task Schedule(Action action) }, Cancellation.Token, TaskCreationOptions.LongRunning, - TaskScheduler.Current).ContinueWith(o => Consumer.Dispose()); + TaskScheduler.Current).ContinueWith(o => Queue.Dispose()); + } + + /// + /// Dispose + /// + public virtual void Dispose() => Cancellation?.Cancel(); + + /// + /// Schedule + /// + /// + /// + public virtual Task Schedule(Action action) + { + var completion = new TaskCompletionSource(); if (Queue.Count > 1) { Queue.TryTake(out var o); } - var completion = new TaskCompletionSource(); - Queue.TryAdd((action, completion)); return completion.Task; diff --git a/Canvas.Views.Web/Canvas.Views.Web.csproj b/Canvas.Views.Web/Canvas.Views.Web.csproj index 301496f..bd8ac33 100644 --- a/Canvas.Views.Web/Canvas.Views.Web.csproj +++ b/Canvas.Views.Web/Canvas.Views.Web.csproj @@ -10,7 +10,7 @@ true True - 1.9.8 + 1.9.9 finance chart opengl canvas trading gdi stock direct2d artemiusgreat indemos.com