public void Cancellation()
 {
     bool raised = false;
     var dis = new NewThreadScheduler ().Schedule<object> (null, TimeSpan.FromMilliseconds (300), (sch, stat) => raised = true);
     Assert.IsFalse (raised, "#1");
     dis.Dispose (); // immediately, to not raise event.
     Thread.Sleep (400);
     Assert.IsFalse (raised, "#2");
 }
예제 #2
0
        public void Cancellation()
        {
            bool raised = false;
            var  dis    = new NewThreadScheduler().Schedule <object> (null, TimeSpan.FromMilliseconds(300), (sch, stat) => raised = true);

            Assert.IsFalse(raised, "#1");
            dis.Dispose();              // immediately, to not raise event.
            Thread.Sleep(400);
            Assert.IsFalse(raised, "#2");
        }
예제 #3
0
파일: Program.cs 프로젝트: marekbar/rx
        private static void CancellRecursive()
        {
            Action <Action> work = (Action self)//will be tranformed to loop internally
                                   =>
            {
                Console.WriteLine("Running");
                self();
            };

            var token = new NewThreadScheduler().Schedule(work);

            Console.ReadLine();
            Console.WriteLine("Cancelling");
            token.Dispose();
            Console.WriteLine("Cancelled");
        }
예제 #4
0
파일: Sandbox.cs 프로젝트: jam40jeff/RxMvvm
 private void RunScheduleAsync(Func<Func<SchedulerOperation>, Task<int>> calculate)
 {
     Console.WriteLine("Running on thread: " + Thread.CurrentThread.ManagedThreadId);
     IObservable<int> observable = Observable.Create<int>(o =>
         {
             IDisposable d = new NewThreadScheduler().ScheduleAsync(async (scheduler, token) =>
                 {
                     o.OnNext(await calculate(scheduler.Yield));
                     o.OnCompleted();
                 });
             return Disposable.Create(() =>
                 {
                     d.Dispose();
                     Console.WriteLine("Disposed!");
                 });
         });
     Console.WriteLine("Subscribing.");
     CompositeDisposable s = new CompositeDisposable();
     for (int i = 0; i < 12; i++)
     {
         s.Add(observable.Subscribe(Console.WriteLine, () => Console.WriteLine("Completed.")));
     }
     Console.WriteLine("Subscribed.");
     Thread.Sleep(700);
     s.Dispose();
     Console.WriteLine("Should have disposed.");
     Thread.Sleep(2000);
     Console.WriteLine("Done.");
 }