static public vCommandAsync <TResult> Create(Func <TResult> command, Predicate <object> canExecute) { var asyncCommand = new vCommandAsync <TResult>(async(cmd) => { var tsk = await System.Threading.Tasks.Task <TResult> .Factory.StartNew(() => { return(command()); }); return(tsk); }, canExecute); return(asyncCommand); }
static public vCommandAsync Create(Action command, Predicate <object> canExecute) { var asyncCommand = new vCommandAsync((cmd) => { var tsk = System.Threading.Tasks.Task.Factory.StartNew(() => { command(); }); return(tsk); }, canExecute); return(asyncCommand); }
static public vCommandAsync Create(Action <CancellationToken> command, Predicate <object> canExecute, CancellationTokenSource cts = null) { if (cts == null) { cts = new CancellationTokenSource(); } var asyncCommand = new vCommandAsync((cmd) => { var tsk = System.Threading.Tasks.Task.Factory.StartNew(() => { command(cts.Token); }); return(tsk); }, canExecute, cts); return(asyncCommand); }
static public vCommandAsync <TResult> Create(Func <CancellationToken, TResult> command, Predicate <object> canExecute, CancellationTokenSource cts = null) { if (cts == null) { cts = new CancellationTokenSource(); } var asyncCommand = new vCommandAsync <TResult>(async(cmd) => { var tsk = await System.Threading.Tasks.Task <TResult> .Factory.StartNew(() => { return(command(cts.Token)); }); return(tsk); }, canExecute, cts); return(asyncCommand); }
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); }