private async Task CopyFile( TargetComputer targetComputer, string file, string destination) { var progressPart = new Progress <FileProgress>( p => { lock (targetComputer.FileSize) { targetComputer.FileSize[file] = p.Total; } lock (targetComputer.FileProgress) { targetComputer.FileProgress[file] = p.Transfered; } targetComputer.JobStatus = JobStatus.Copying; if (p.Transfered >= p.Total) { targetComputer.JobStatus = JobStatus.Success; } Dispatcher.InvokeAsync(RecomputeTotals); }); try { await FileEx.CopyAsync( file, destination, cancellationTokenSource.Token, progressPart); } catch (Win32Exception wex) { targetComputer.JobStatus = JobStatus.Failed; targetComputer.Exception = wex; } catch (OperationCanceledException) { if (targetComputer.JobStatus == JobStatus.Copying || targetComputer.JobStatus == JobStatus.Waiting) { targetComputer.JobStatus = JobStatus.Cancelled; } throw; } }