12/5/2023 0 Comments Corsair 5000 cases![]() Since Start() and Stop() will no-longer work, should this also cancel the operation? Indeed, they ought to throw ObjectDisposedExceptions when called on a disposed instance. This is not a 'nice' implementation of IDisposable, but assuming the underlying types implement it well, then it's fine. _scheduledTask can not be null here under correct usage, so remove the check: all it can do is obscure insidious bugs later. It will behave the same way if the task decides to throw OperationCanceledException() for any reason, so Stop() may not be in position to deal with it.Ī solution (if there is a problem) might be as simple as adding a finally with _isStarted = false to the try within _scheduledTask. I don't know what the behaviour should be, but this seems wrong, not least because it is impossible (and wouldn't make sense) query whether the task is running. / Gets the running status of the TimerAsync instance. / Occurs when an error is raised in the scheduled action ![]() ![]() Private readonly bool _canStartNextActionBeforePreviousIsCompleted Private readonly SemaphoreSlim _semaphore / a thread pool thread at specified intervals. / Provides a mechanism for executing an async method on _scheduledAction = scheduledAction ? throw new ArgumentNullException(nameof(scheduledAction)) Īwait Task.Delay(_dueTime, _cancellationSource.Token) Īwait _scheduledAction(_cancellationSource.Token) Īwait Task.Delay(_period, _cancellationSource.Token) Public TimerAsync(Func scheduledAction, TimeSpan dueTime, TimeSpan period) Private readonly SemaphoreSlim _startSemaphore = new SemaphoreSlim(1) Private CancellationTokenSource _cancellationSource Hidden cable management and an airflow-optimized front panel. Public sealed class TimerAsync : IDisposable The CORSAIR 5000D AIRFLOW is a mid-tower ATX case that shows off your PC, and not its cables. Here's the code, can you please review it and point out any flaw you can find? using System only one action should be running at any given time (period countdown should start when the previous action has been terminated).I'm trying to implement a Timer that schedule an async action with the following requirements:
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |