Playing poker next Saturday night & want to impress your friends with your programming skills?
The following solution requires LINQPad Beta release; It uses the new DumpLive feature allowing you to render reactive streams of WPF UI Elements!
Enjoy!
(from round in new[] { new{Small = 5, Big = 10, Length = 16}, new{Small = 10, Big = 20, Length = 20}, new{Small = 20, Big = 40, Length = 20}, new{Small = 100, Big = 200, Length = 20}, new{Small = 300, Big = 600, Length = 20}, new{Small = 600, Big = 1200, Length = 20}, new{Small = 1000, Big = 2000, Length = 20}, new{Small = 5000, Big = 10000, Length = 20}, new{Small = 30000, Big = 60000, Length = 20}, new{Small = 100000, Big = 200000, Length = 20}, } let ts = TimeSpan.FromMinutes(round.Length) select from tick in Observable.Interval(TimeSpan.FromSeconds(1)).TakeUntil(Observable.Timer(ts)) let remaining = ts.Subtract(TimeSpan.FromSeconds(tick)) select new{ text = string.Format("Small: {0}\r\nBig: {1}\r\nRemaining: {2}", round.Small, round.Big, remaining), colour = remaining < TimeSpan.FromMinutes(1) ? Brushes.Red : Brushes.Black }) .Concat() .ObserveOnDispatcher() .Select(x => new TextBlock{Text = x.text, FontSize = 80, Foreground = x.colour}) .DumpLive();
OUTPUT




March 27, 2012 at 9:06 pm
I am having trouble to get this snippet to work. Which additional references and additional namespaces were used in Linqpad? (I am using LP 4.40.03 but still cannot see the DumpLive() method in the intellisense?)
March 28, 2012 at 7:18 am
Could you provide some more details?
Make sure you are using the latest beta release of LINQPad (http://www.linqpad.net/Beta.aspx)
April 1, 2012 at 11:43 am
thanks for getting back James,
I think I am using the latest beta version, LINQPad 4.40.03.
http://imgur.com/SAnlk
I have the query working except the ObserveOnDispatcher line.
with the original query I get this:
http://imgur.com/h6E2K
(I think the reason may be that I have the latest beta of RX (2.0))
if I comment out the observeondispatcher I get this:
http://imgur.com/peY3x
Any ideas how to circumvent this or get the observeondispatcher method to work?
April 2, 2012 at 4:22 am
Hi Henrik,
It looks like you might be missing a reference to;
System.Reactive.Windows.Threading.dll
April 2, 2012 at 4:39 pm
indeed, that is what it was, working fine now. Many thanks for help James!