public IDisposable Subscribe(IObserver <PerfTestResult> observer) { if (ignoreFirstRunDueToJITting) { this.setUpMethod(this.start); try { this.testMethod(); } catch (Exception ex) { } this.tearDownMethod(); } var time = new DurationMonitor(); var memory = new MemoryMonitor(); for (var i = this.start; i < this.end; i += this.step) { var ok = true; var descriptor = this.descriptorMethod(i); this.setUpMethod(i); // clean memory if (this.triggerGCBeforeEachTest) { GC.Collect(); GC.WaitForPendingFinalizers(); GC.Collect(); } using (time.Observe()) using (memory.Observe()) { try { this.testMethod(); } catch (Exception ex) { ok = false; observer.OnNext(PerfTestResultFactory.Instance.FaultResult(descriptor, ex)); } } this.tearDownMethod(); if (ok) { observer.OnNext(PerfTestResultFactory.Instance.PerfResult(time.Value, memory.Value, descriptor)); } } return(new DisposableScope()); }
private async Task ShowAsync(Snackbar snackbar, SnackbarMessageQueueItem messageQueueItem) { await Task.Run(async() => { //create and show the message, setting up all the handles we need to wait on var actionClickWaitHandle = new ManualResetEvent(false); var mouseNotOverManagedWaitHandle = await snackbar.Dispatcher.InvokeAsync( () => CreateAndShowMessage(snackbar, messageQueueItem, actionClickWaitHandle)); var durationPassedWaitHandle = new ManualResetEvent(false); DurationMonitor.Start(messageQueueItem.Duration.Add(snackbar.ActivateStoryboardDuration), _pausedEvent, durationPassedWaitHandle, _disposedEvent); //wait until time span completed (including pauses and mouse overs), or the action is clicked await WaitForCompletionAsync(mouseNotOverManagedWaitHandle, durationPassedWaitHandle, actionClickWaitHandle); //close message on snackbar await snackbar.Dispatcher.InvokeAsync( () => snackbar.SetCurrentValue(Snackbar.IsActiveProperty, false)); //we could wait for the animation event, but just doing //this for now...at least it is prevent extra call back hell _disposedEvent.WaitOne(snackbar.DeactivateStoryboardDuration); //remove message on snackbar await snackbar.Dispatcher.InvokeAsync( () => snackbar.SetCurrentValue(Snackbar.MessageProperty, null)); mouseNotOverManagedWaitHandle.Dispose(); durationPassedWaitHandle.Dispose(); }) .ContinueWith(t => { if (t.Exception == null) { return; } var exc = t.Exception.InnerExceptions.FirstOrDefault() ?? t.Exception; Trace.WriteLine("Error occured whilst showing Snackbar, exception will be rethrown."); Trace.WriteLine($"{exc.Message} ({exc.GetType().FullName})"); Trace.WriteLine(exc.StackTrace); throw t.Exception; }); }
public void CanUseDurationMonitor() { var monitor = new DurationMonitor(); monitor.Value.Should().Be(0); using (monitor.Observe()) { } var value1 = monitor.Value; value1.Should().NotBe(0); using (monitor.Observe()) { Thread.Sleep(20); } var value2 = monitor.Value; value2.Should().NotBe(0); (value1 < value2).Should().BeTrue(); }
public void CanUseDurationMonitor() { var monitor = new DurationMonitor(); monitor.Value.Should().Be(0); using (monitor.Observe()) { } var value1 = monitor.Value; value1.Should().NotBe(0); using (monitor.Observe()) { Thread.Sleep(20); } var value2 = monitor.Value; value2.Should().NotBe(0); (value1 < value2).Should().BeTrue(); }