private async Task SendCStoreRequest(OutputJob job) { await DownloadFromPayloadsService(job); if (job.PendingDicomFiles.Count > 0) { var countDownEventHandle = new CountdownEvent(job.PendingDicomFiles.Count); DicomClient client = null; try { client = new DicomClient( job.HostIp, job.Port, false, _dicomAdapterConfiguration.Value.Dicom.Scu.AeTitle, job.AeTitle); client.AssociationAccepted += (sender, args) => job.Logger.LogInformation("Association accepted."); client.AssociationRejected += (sender, args) => job.Logger.LogInformation("Association rejected."); client.AssociationReleased += (sender, args) => job.Logger.LogInformation("Association release."); client.Options = new DicomServiceOptions { LogDataPDUs = _dicomAdapterConfiguration.Value.Dicom.Scu.LogDataPdus, LogDimseDatasets = _dicomAdapterConfiguration.Value.Dicom.Scu.LogDimseDatasets }; client.NegotiateAsyncOps(); GenerateRequests(job, client, countDownEventHandle); job.Logger.LogInformation("Sending job to {0}@{1}:{2}", job.AeTitle, job.HostIp, job.Port); await client.SendAsync(_token).ConfigureAwait(false); countDownEventHandle.Wait(_token); job.Logger.LogInformation("Job sent to {0} completed", job.AeTitle); } catch (Exception ex) { HandleCStoreException(ex, job, client); } } job.LogFailedRequests(); job.ReportStatus(_token); }