IEnumerable<Tag> ParseTags(ExifToolResult result) { var tags = Options.Parser.ParseTags(result.Output); _process.Dispose(); return tags; }
// http://stackoverflow.com/questions/10788982/is-there-any-async-equivalent-of-process-start Task<ExifToolResult> RunProcessAsync(ProcessStartInfo psi, Stream stream) { var tcs = new TaskCompletionSource<ExifToolResult>(); _process = new Process { StartInfo = psi, EnableRaisingEvents = true }; _process.Exited += (sender, args) => { var result = new ExifToolResult { Output = _process.StandardOutput }; tcs.SetResult(result); }; try { _process.Start(); if(stream != null) { stream.CopyTo(_process.StandardInput.BaseStream); _process.StandardInput.Flush(); _process.StandardInput.Dispose(); } } catch (Win32Exception ex) { throw new Exception("Error when trying to start the exiftool process. Please make sure exiftool is installed, and its path is properly specified in the options.", ex); } return tcs.Task; }