Пример #1
0
        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);
        }
Пример #2
0
        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);
        }
Пример #3
0
        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);
        }
Пример #4
0
        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);
        }
Пример #5
0
        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);
        }