Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using System;
- using System.Collections.Concurrent;
- using System.Reactive.Concurrency;
- using System.Reactive.Linq;
- namespace ConsoleApplication1
- {
- class Program
- {
- static void Main ()
- {
- var q = new BlockingCollection<int>();
- var r = new Random();
- int id = 1;
- using (Observable
- .Timer(TimeSpan.Zero, TimeSpan.FromSeconds(1), new EventLoopScheduler())
- .Subscribe(x => {
- var v = q.Take();
- /*int v;
- if (q.TryTake(out v))*/
- Console.WriteLine("{0}: {1} ({2})", DateTime.Now, v, q.Count);
- }))
- using (Observable
- .Timer(TimeSpan.Zero, TimeSpan.FromSeconds(3), new EventLoopScheduler())
- .Subscribe(x => {
- int n = r.Next(0, 5);
- for (int i = 0; i < n; ++i)
- q.Add(id++);
- })) {
- Console.ReadLine();
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement