Пример #1
0
        private bool _disposedValue = false; // To detect redundant calls

        protected virtual void Dispose(bool disposing)
        {
            if (!_disposedValue)
            {
                if (disposing)
                {
                    // dispose managed state (managed objects).
                    BlockCypherClient?.Dispose();
                    if (DisposeTorControl)
                    {
                        try
                        {
                            TorControlPortClient?.DisconnectDisposeSocket();
                        }
                        catch
                        {
                            // ignored
                        }
                    }
                }

                // free unmanaged resources (unmanaged objects) and override a finalizer below.
                // set large fields to null.

                _disposedValue = true;
            }
        }
Пример #2
0
        public async Task StartAsync(CancellationToken ctsToken)
        {
            while (true)
            {
                try
                {
                    await Semaphore.WaitAsync(ctsToken).ConfigureAwait(false);

                    if (ctsToken.IsCancellationRequested)
                    {
                        return;
                    }

                    if (TorControlPortClient != null)
                    {
                        await TorControlPortClient.ChangeCircuitAsync(ctsToken).ConfigureAwait(false);
                    }

                    var generalInfo = await BlockCypherClient.GetGeneralInformationAsync(ctsToken).ConfigureAwait(false);

                    _lowFee    = generalInfo.LowFee;
                    _mediumFee = generalInfo.MediumFee;
                    _highFee   = generalInfo.HighFee;

                    if (ctsToken.IsCancellationRequested)
                    {
                        return;
                    }
                    _firstRun = false;
                }
                catch (OperationCanceledException)
                {
                    if (ctsToken.IsCancellationRequested)
                    {
                        return;
                    }
                    continue;
                }
                catch (Exception ex)
                {
                    if (_firstRun)
                    {
                        throw;
                    }

                    Debug.WriteLine($"Ignoring {nameof(FeeService)} exception:");
                    Debug.WriteLine(ex);
                }
                finally
                {
                    Semaphore.SafeRelease();
                }

                var waitMinutes = new Random().Next(3, 10);
                await Task.Delay(TimeSpan.FromMinutes(waitMinutes), ctsToken).ContinueWith(t => { }).ConfigureAwait(false);
            }
        }