public void From(ProgressVM other) { this.Name = other.Name; this.Progress = other.Progress; this.SubName = other.SubName; this.SubProgress = other.SubProgress; }
async static public Task ExecuteActionAsync(CancellationToken token, ProgressVM progress, Action <CancellationToken, ProgressVM, Action> action) { var prgrs = new ProgressVM(); prgrs.From(progress); await System.Threading.Tasks.Task.Factory.StartNew(() => { action(token, prgrs, () => { progress.From(prgrs); }); }); }
async static public Task <TResult> ExecuteFuncAsync(CancellationToken token, ProgressVM progress, Func <CancellationToken, ProgressVM, Action, TResult> func) { var prgrs = new ProgressVM(); prgrs.From(progress); var tsk = await System.Threading.Tasks.Task <TResult> .Factory.StartNew(() => { return(func(token, prgrs, () => { progress.From(prgrs); })); }); return(tsk); }
static public vCommandAsync Create(ProgressVM progress, Action <CancellationToken, ProgressVM, Action> command, Predicate <object> canExecute, CancellationTokenSource cts = null) { if (cts == null) { cts = new CancellationTokenSource(); } var prgrs = new ProgressVM(); prgrs.From(progress); var asyncCommand = new vCommandAsync((cmd) => { var tsk = System.Threading.Tasks.Task.Factory.StartNew(() => { command(cts.Token, prgrs, () => { progress.From(prgrs); }); }); return(tsk); }, canExecute, cts); return(asyncCommand); }