Example #1
0
            /// <inheritdoc />
            protected override async Task OnSendQueueEmptyAsync()
            {
                var lingerCancellationTokenSource = new CancellationTokenSource();

                void CancelLingering(string reason)
                {
                    if (!lingerCancellationTokenSource.IsCancellationRequested)
                    {
                        Logger.Debug($"Won't linger association because {reason}");
                        lingerCancellationTokenSource.Cancel();
                    }
                }

                var newRequestsComeIn = _client._hasRequestsFlag.WaitAsync()
                                        .ContinueWith(_ => CancelLingering("another DICOM request was just added"),
                                                      TaskContinuationOptions.OnlyOnRanToCompletion);
                var nextRequestsAreSent = _client.SendQueuedRequestsAsync()
                                          .ContinueWith(requestsWereSent =>
                {
                    if (requestsWereSent.Result)
                    {
                        CancelLingering("another DICOM request was just sent");
                    }
                }, TaskContinuationOptions.OnlyOnRanToCompletion);
                var lingerAssociation = Task.Delay(_client.Linger, lingerCancellationTokenSource.Token)
                                        .ContinueWith(async _ => await LingerAsync(DefaultReleaseTimeout), TaskContinuationOptions.OnlyOnRanToCompletion);

                await Task.WhenAny(newRequestsComeIn, nextRequestsAreSent, lingerAssociation)
                .ConfigureAwait(false);
            }
Example #2
0
 /// <inheritdoc />
 protected override async Task OnSendQueueEmptyAsync()
 {
     await Task.WhenAny(
         _client.SendQueuedRequestsAsync(),
         _isDisconnectedFlag.WaitAsync()
         .ContinueWith(_ => SetCompletionFlag(), TaskContinuationOptions.OnlyOnRanToCompletion),
         Task.Delay(_client.Linger)
         .ContinueWith(_ => DoSendAssociationReleaseRequestAsync(DefaultReleaseTimeout),
                       TaskContinuationOptions.OnlyOnRanToCompletion)).ConfigureAwait(false);
 }