Wednesday, March 14, 2012

Reactive Extensions Gems

As I am learning about reactive extensions I want to post some code that I think is useful. Before using the code here you may want to download Reactive Extensions for your .Net Framework version. It is located at http://www.microsoft.com/download/en/details.aspx?id=24940

Observable.Interval(TimeSpan.FromSeconds(1)).Subscribe(DoSomething);
What it does: it will call a method called DoSomething that acceptes one parameter of type long.
What can you do with it: You can use this line to call the DoSomething every second and send emails for example. before this line you can retrieve the list of customers to send emails to, and every second grab one customer and send email to him/her

Observable.Timer(TimeSpan.FromSeconds(5),TimeSpan.FromSeconds(1)).Subscribe(DoSomething);
What it does: Call a method every second after waiting for three seconds initially.
What you can do with it: You can send emails to customers after waiting a specific perdiod of time.

No comments: