Skip to content

Instantly share code, notes, and snippets.

@benhysell
Last active October 7, 2016 11:53
Show Gist options
  • Save benhysell/9c00407d7b0550494e3e to your computer and use it in GitHub Desktop.
Save benhysell/9c00407d7b0550494e3e to your computer and use it in GitHub Desktop.
Rx Timer Example
Action work = () =>Console.Writeln("work!");
Scheduler.Default.Schedule(
// start in so many seconds
TimeSpan.FromSeconds(60 - DateTime.Now.Second),
// then run every minute
() => Scheduler.Default.SchedulePeriodic(TimeSpan.FromMinutes(1), work));
//create a timer to trigger the event change in the future
var timer = Observable.Timer(DateTimeOffset.Now.AddMilliseconds(sendDelay.Value));
timer.Subscribe(_ =>
{
var handler = RaiseMessageSendEvent;
if (null != handler)
handler(this, new MessageEventArguments(response));
});
/// <summary>
/// Future change events
/// </summary>
CompositeDisposable futureSignalChangeEvents;
/// <summary>
/// clear out all old timers
/// </summary>
private void Reset()
{
//clear out all old timers
futureSignalChangeEvents.Dispose();
futureSignalChangeEvents = new CompositeDisposable();
}
public void CreateFutureEvent()
{
//create a timer to trigger the event change in the future
var timer = Observable.Interval(TimeSpan.FromMilliseconds(100))
.Subscribe(
x =>
{
//do work here
});
futureSignalChangeEvents.Add(futureEventSubscription);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment