public virtual FileSystemExitCode PutFile(string localName, RemotePath remoteName, CopyFlags copyFlags) { try { // My ThreadKeeper class is needed here because calls to ProgressProc must be made from this thread and not from some random async one. using (var exec = new ThreadKeeper()) { void Progress(int percentDone) { exec.RunInMainThread(() => { if (ProgressProc(localName, remoteName, percentDone)) { exec.Cancel(); } }); } var ret = exec.ExecAsync(asyncFunc: (token) => PutFileAsync(localName, remoteName, copyFlags, Progress, token)); return(ret); } } catch (TaskCanceledException) { return(FileSystemExitCode.UserAbort); } catch (OperationCanceledException) { return(FileSystemExitCode.UserAbort); } catch (AggregateException e) { if (HasCanceledException(e)) { return(FileSystemExitCode.UserAbort); } throw; } }
public void Report(int value) { _exec.RunInMainThread(() => { try { _parrentProgress.Report(value); } catch (TaskCanceledException) { _exec.Cancel(); } }); }