private void Go(IBackgroundTaskContext context) { string studyUid = DicomUid.GenerateUid().UID; string seriesUid = DicomUid.GenerateUid().UID; PixelAspectRatioChanger changer = new PixelAspectRatioChanger { IncreasePixelDimensions = _component.IncreasePixelDimensions, NewAspectRatio = new PixelAspectRatio(_component.AspectRatioRow, _component.AspectRatioColumn), RemoveCalibration = _component.RemoveCalibration }; int i = 0; context.ReportProgress(new BackgroundTaskProgress(i, _dicomFileNames.Count, "Exporting ...")); try { foreach (string originalFile in _dicomFileNames) { var file = new DicomFile(originalFile); file.Load(DicomReadOptions.None); string sopInstanceUid = DicomUid.GenerateUid().UID; file.DataSet[DicomTags.StudyInstanceUid].SetStringValue(studyUid); file.DataSet[DicomTags.SeriesInstanceUid].SetStringValue(seriesUid); file.DataSet[DicomTags.SopInstanceUid].SetStringValue(sopInstanceUid); changer.ChangeAspectRatio(file); string outputFileName = Path.Combine(_outputDirectory, String.Format("{0}.dcm", sopInstanceUid)); file.Save(outputFileName); if (context.CancelRequested) { context.Cancel(); return; } context.ReportProgress(new BackgroundTaskProgress(++i, _dicomFileNames.Count + 1, "Exporting ...")); } } catch (Exception e) { context.Error(e); return; } context.Complete(); }