Skip to content

Instantly share code, notes, and snippets.

@rasoulian
Created July 2, 2018 09:59
Show Gist options
  • Save rasoulian/4be3597ac3845dc94e1ac0023277d9ae to your computer and use it in GitHub Desktop.
Save rasoulian/4be3597ac3845dc94e1ac0023277d9ae to your computer and use it in GitHub Desktop.
ReactiveScheduler
namespace Scheduler
{
class Program
{
static void Main(string[] args)
{
Scheduling.ScheduleWithEnd();
Scheduling.ScheduleWithoutEnd();
Console.ReadKey();
}
}
}
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