public void Can_run_in_background() { const int ticks = 3; var block = new ManualResetEvent(false); RegisterMetrics(); ThreadPool.QueueUserWorkItem( s => { var reporter = new ConsoleReporter(); reporter.Start(3, TimeUnit.Seconds); while (true) { Thread.Sleep(1000); var runs = reporter.Runs; if (runs == ticks) { block.Set(); } } } ); block.WaitOne(TimeSpan.FromSeconds(5)); }
public void Can_stop() { var block = new ManualResetEvent(false); RegisterMetrics(); ThreadPool.QueueUserWorkItem( s => { var reporter = new ConsoleReporter(); reporter.Start(1, TimeUnit.Seconds); reporter.Stopped += delegate { block.Set(); }; Thread.Sleep(2000); reporter.Stop(); }); block.WaitOne(); }
public static void Main(string[] args) { Console.WriteLine(typeof(Exception).IsAssignableFrom(typeof(ArgumentNullException))); Console.WriteLine(typeof(ArgumentNullException).IsAssignableFrom(typeof(Exception))); IKernel kernel = new StandardKernel(); MetricRegistry registry = new MetricRegistry(); kernel.Bind <MetricRegistry>().ToConstant <MetricRegistry>(registry); Tryout t = kernel.Get <Tryout>(); ConsoleReporter reporter = ConsoleReporter.ForRegistry(registry).build(); reporter.Start(1, TimeUnit.Seconds); Graphite sender = new Graphite("ttolley-lap3", 2003); GraphiteReporter greporter = GraphiteReporter.ForRegistry(registry).Build(sender); greporter.Start(10, TimeUnit.Seconds); int i = 0; Random r = new Random(); for (; i < 10000; i++) { try { t.Test(r.Next(101)); } catch { // Do nothing } } Console.WriteLine("Done counting"); for (i = 0; i < 10; i++) { Thread.Sleep(60000); } }
/// <summary> /// Enables the console reporter and causes it to print to STDOUT with the specified period /// </summary> /// <param name="period">The period between successive outputs</param> /// <param name="unit">The time unit of the period</param> public void EnableConsoleReporting(long period, TimeUnit unit) { var reporter = new ConsoleReporter(this); reporter.Start(period, unit); }