public void MoveOutputFiles() { //Ensure the the first file is the first in TempOutputFiles TempOutputFiles = TempOutputFiles.OrderBy(x => x).ToList(); _outfilebody = DetermineOutfileBody(); var isFirstFile = true; foreach (var tempOutputFile in TempOutputFiles) { var extension = PathSafe.GetExtension(tempOutputFile); var num = DetermineNumWithDigits(tempOutputFile); _currentOutputFile = _outfilebody + num + extension; //first file in interactive workflow if (isFirstFile && !Profile.AutoSave.Enabled && OnRetypeOutputFilename != null) { if (!CopyFileWithInteractiveOutputFilenameTemplateQuery(tempOutputFile, num, extension)) { return; //cancelled by user } } else { lock (LockObject) { var uniqueFilename = new UniqueFilename(_currentOutputFile, DirectoryWrap, FileWrap); if (Profile.AutoSave.Enabled && Profile.AutoSave.EnsureUniqueFilenames) { _currentOutputFile = EnsureUniqueFilename(uniqueFilename); } if (!CopyFile(tempOutputFile, _currentOutputFile)) { _currentOutputFile = EnsureUniqueFilename(uniqueFilename); if (!CopyFile(tempOutputFile, _currentOutputFile)) { //Throw exception after second attempt to copy failes. throw new DeviceException( "Error while copying to target file in second attempt. Process gets canceled.", 2); } } } } DeleteFile(tempOutputFile); OutputFiles.Add(_currentOutputFile); isFirstFile = false; } OutputFiles = OutputFiles.OrderBy(x => x).ToList(); }