public CalculatorViewModel() { _cache = new MemoizingMRUCache <int, int>((x, ctx) => { Thread.Sleep(1000); // Pretend this calculation isn’t cheap return(x * 10); }, 5); CalculateCommand = new ReactiveCommand(this.WhenAny(x => x.Number, x => x.Value > 0)); (CalculateCommand as ReactiveCommand).RegisterAsyncTask(o => { return(Task.Factory.StartNew(() => { int top; bool cached = _cache.TryGet(Number, out top); if (cached) { Result = 0; Thread.Sleep(1000); Result = top; } else { top = _cache.Get(Number); for (int i = 0; i <= top; i++) { Result = i; Thread.Sleep(100); } } })); }); }
public CalculatorViewModel() { _reactiveHelper = new MakeObjectReactiveHelper(this); _cache = new MemoizingMRUCache<int, int>((x, ctx) => { Thread.Sleep(1000); // Pretend this calculation isn’t cheap return x*10; }, 5); CalculateCommand = new ReactiveAsyncCommand(this.WhenAny(x => x.Number, x => x.Value > 0)); (CalculateCommand as ReactiveAsyncCommand).RegisterAsyncTask<object>(o => { return Task.Factory.StartNew(() => { int top; bool cached = _cache.TryGet( Number, out top); if (cached) { Result = 0; Thread.Sleep(1000); Result = top; } else { top = _cache.Get(Number); for (int i = 0; i <= top; i++) { Result = i; Thread.Sleep(100); } } }); }); }
public CalculatorViewModel() { _cache = new MemoizingMRUCache<int, int>((x, ctx) => { Thread.Sleep(1000); // Pretend this calculation isn’t cheap return x*10; }, 5); CalculateCommand = ReactiveCommand.CreateAsyncTask<object>( this.WhenAnyValue(x => x.Number, x => x > 0), o => { return Task<object>.Factory.StartNew(() => { int top; bool cached = _cache.TryGet( Number, out top); if (cached) { Result = 0; Thread.Sleep(1000); Result = top; } else { top = _cache.Get(Number); for (int i = 0; i <= top; i++) { Result = i; Thread.Sleep(100); } } return null; }); }, RxApp.MainThreadScheduler); }
public CalculatorViewModel() { _cache = new MemoizingMRUCache <int, int>((x, ctx) => { Thread.Sleep(1000); // Pretend this calculation isn’t cheap return(x * 10); }, 5); CalculateCommand = ReactiveCommand.CreateAsyncTask <object>( this.WhenAnyValue(x => x.Number, x => x > 0), o => { return(Task <object> .Factory.StartNew(() => { int top; bool cached = _cache.TryGet(Number, out top); if (cached) { Result = 0; Thread.Sleep(1000); Result = top; } else { top = _cache.Get(Number); for (int i = 0; i <= top; i++) { Result = i; Thread.Sleep(100); } } return null; })); }, RxApp.MainThreadScheduler); }
public CalculatorViewModel() { _cache = new MemoizingMRUCache<int, int>((x, ctx) => { Thread.Sleep(1000); // Pretend this calculation isn’t cheap return x*10; }, 5); CalculateCommand = ReactiveCommand.CreateAsyncTask(o => { return Task.Factory.StartNew(() => { int top; bool cached = _cache.TryGet( Number, out top); if (cached) { Result = 0; Thread.Sleep(1000); Result = top; } else { top = _cache.Get(Number); for (int i = 0; i <= top; i++) { Result = i; Thread.Sleep(100); } } }); }); }