private bool CopyFile(string source, string destination, out bool restartRequired) { restartRequired = false; if (LockedFilesWatcher.Instance.LockedFiles.Contains(destination)) { restartRequired = true; } Directory.CreateDirectory(Path.GetDirectoryName(destination)); Stream output = null; try { output = FileSystemExtensions.CreateFileWithRetry(destination, 2, 500); } catch (IOException) { _lockedFiles.Add(destination); restartRequired = true; } if (output == null) { Logger.Error($"Creation of file {destination} failed"); return(false); } using (output) { using var sourceStream = new FileStream(source, FileMode.Open, FileAccess.Read); sourceStream.CopyTo(output); } return(true); }