async Task updateAwailablePortsLoop(CancellationToken cancellation) { await ThreadingUtils.ContinueAtDedicatedThread(cancellation); var period = new PeriodDelay(1000); while (true) { try { using (await Locker.AcquireAsync()) { var devices = getAllDevices(); PortNames = devices.Length.Range().Select(i => PORT_PREFIX + i); } } catch (OperationCanceledException) { throw; } catch (Exception ex) { Logger.LogError(null, $"Ошибка обновления списка устройств", ex); } await period.WaitTimeLeftAsync(cancellation); } }
public async Task <IAsyncDisposable> EnterAsync(string key, CancellationToken cancellationToken = default) { var locker = new Locker($"lock:{key}", _client, _options.CurrentValue.LockExpiry); using (_acquireOngoing.TrackInProgress()) await locker.AcquireAsync(cancellationToken); _acquires.Inc(); return(locker); }