Created
January 26, 2014 22:30
-
-
Save daanl/8640316 to your computer and use it in GitHub Desktop.
RxTimer
This file contains hidden or 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.Reactive.Linq; | |
using System.Threading.Tasks; | |
namespace RxTimer | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var isBusy = false; | |
var interval = Observable.Interval(TimeSpan.FromSeconds(1)); | |
interval.Where(x => !isBusy) | |
.Subscribe(async (item) => | |
{ | |
isBusy = true; | |
Console.WriteLine("Doing some background work: {0}", DateTime.UtcNow); | |
await Task.Delay(TimeSpan.FromSeconds(2)); | |
Console.WriteLine("Done doing some background work: {0}", DateTime.UtcNow); | |
isBusy = false; | |
}); | |
Console.ReadLine(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment