Created
July 2, 2018 09:59
-
-
Save rasoulian/4be3597ac3845dc94e1ac0023277d9ae to your computer and use it in GitHub Desktop.
ReactiveScheduler
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
namespace Scheduler | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
Scheduling.ScheduleWithEnd(); | |
Scheduling.ScheduleWithoutEnd(); | |
Console.ReadKey(); | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
using System.Linq; | |
using System.Reactive.Linq; | |
using System.Text; | |
using System.Threading.Tasks; | |
namespace Scheduler | |
{ | |
static class Scheduling | |
{ | |
static void ScheduleWithEnd() | |
{ | |
Observable.Defer(() => | |
DateTime.Now.Hour < 19 | |
? Observable.Timer(DateTime.Today.AddHours(9)) | |
: DateTime.Now.Hour < 13 | |
? Observable.Timer(DateTime.Today.AddHours(13)) | |
: Observable.Timer(DateTime.Today.AddDays(1).AddHours(9))) | |
.Repeat(10) | |
.Subscribe(id => { Console.WriteLine("Hi" + System.Threading.Thread.CurrentThread.ManagedThreadId); }); | |
} | |
static void ScheduleWithoutEnd() | |
{ | |
var clock = from _ in Observable.Interval(TimeSpan.FromSeconds(1)) | |
select DateTime.Now; | |
clock.Subscribe(now => | |
{ | |
Console.WriteLine("It's now {0} o'clock", now); | |
}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment