Skip to main content

Posts

Implementing a busy indicator using a visual overlay in MVVM

This is a technique we use at work to lock the UI whilst some long running process is happening - preventing the user clicking on stuff whilst it's retrieving or rendering data. Now we could have done this by launching a child dialog window but that feels rather out of date and clumsy, we wanted a more modern pattern similar to the way <div> overlays are done on the web. Imagine we have the following simple WPF app and when 'Click' is pressed a busy waiting overlay is shown for the duration entered into the text box. What I'm interested in here is not the actual UI element of the busy indicator but how I go about getting this to show & hide from when using MVVM. The actual UI elements are the standard Busy Indicator coming from the WPF Toolkit : The XAML behind this window is very simple, the important part is the ViewHost. As you can see the ViewHost uses a ContentPresenter element which is bound to the view model, IMainViewModel, it contains 3 child v...

Comparing performance of .Net 4.5 to .Net 4.0 for WPF

Currently I'm working on a .Net 4.0 WPF app and we've had some discussion about moving to .Net 4.5, we don't get to make the decision :( but we're interested to know what performance gain we'd get. What follows is a comparison of the same app compiled against .Net 4.0 & 4.5. The app makes use of a couple of NuGet packages - Autofac & Reactive Extensions, both of which provide versions for both .Net 4.0 & 4.5. It also makes use of Telerik grid control to render the data. What does the app do? Pretty simple, it generates a 1000 rows of data asynchronously and binds this to a telerik grid, for every iteration the grid is clear of any data first. How am I going to measure any performance improvement? I'm using the code from a previous post - ' Measuring UI Freeze... ', I'm expecting any improvement to be visible in a reduced amount of time on the dispatcher thread - if the (.Net) code base is more efficient it should surely redu...

Measuring UI freeze in WPF applications with Reactive Extensions

Making sure an application doesn't freeze the UI is probably one of the most important concerns when building an application. UI freeze can be broken down into two categories,firstly long running background tasks and secondly the rendering of UI elements (controls) to the screen. The second situation is what interests me with this post, usually UI based applications will dedicate a single thread to rendering the UI (dispatcher). This thread in theory can become overloaded with work and therefore the UI  becomes unresponsive to the user until the work is completed - the app freezes. Measuring this freeze on the dispatcher is useful in diagnosing the problems of rendering large amounts of data in a short time frame, e.g. like trying to render a large number of rows in a grid. How can I measure this freeze? You can do this easily with a couple of Rx methods: Loading .... The key is making sure they execute on the dispatcher thread. This ensures that when the dispatcher is ov...

Using dynamic data with Telerik RadPivotGrid

Using the Telerik RadPivotGrid is a great way to render out financial data such as balance sheets,  a UI can be knocked up very quickly: The issue with this is you're required to use strongly typed entities (classes), what do I mean by this? I mean the class being bound to the control has to have explicitly named properties which will be used for the columns and rows in the pivot grid. The ' Getting Started ' pages on the Telerik website show how to use a collection of the following entity: The binding is done in XAML: As you can see the properties of the Name class are explicitly defined, this provider resource is then used as follows: This gives you the following output: I don't have a strongly typed entity, so what am I going to do? What follows is a way to binding data with no structure, when I say no structure I mean the data is no more than name-value pairs or more commonly known as a dictionary\map. I've split the metadata from the dat...

Using Windows update agent object model to get all installed hotfixes (KBs)

A simple bit of code to get all the installed hot-fixes for an MS operating system - we do this so we can log any machines in the enterprise missing the required patches. Windows update agent object model or WuApi makes this very easy - just add a reference to the WuApi COM interop library and you're away. You'll see below I'm using regular expression to match the hotfix naming convention, e.g. KB2484841. Loading .... I'm using a custom disposable object call ComDisposable and an extension method to add the COM interop types to the ComDisposble, these are there just to make sure they get cleared down at the end: Loading ....

Reactive Extensions Plugin for Resharper

A quick post to introduce a new Resharper plugin for Visual Studio to hopefully help when writing code using the Reactive Extensions libraries. The background to how I came to developing this plugin is simple - @leeoades , @hamishdotnet & I were looking into a regression bug we introduced where the app completely froze - a classic blocking issue on the UI thread. We knew this because the host for the app (web browser) was complete unresponsive, the app (which happened to be Silverlight) had completely locked up the UI thread, leaving even the browser chrome useless - the only thing left was to kill the process. We do a lot of asynchronous stream processing using Rx and we knew one of the extension method from the Rx libraries was causing synchronization dead lock by scheduling work onto the UI thread. Now we knew the issue wasn't with the actual methods from the Rx libraries but how they were being used. We weren't using an overload for one of the Rx extension metho...

Unit testing Rx methods Timeout & Retry with moq

Earlier this week I was trying to unit test an asynchronous service (Foo) which used another asynchronous service (Bar) internally and ran into an issue trying to mock out the Bar service so that it would cause the retry & timeout schedules to fire. Bar is defined as follows, the implementation is irrelevant as it being mocked for the tests: 1: public interface IBarService 2: { 3: IObservable<Unit> Generate(); 4: } Foo is similarly defined: 1: public interface IFooService 2: { 3: IObservable<Unit> Generate(); 4: } The implementation of the Foo service is the important part, it uses the Boo service to generate a value, it's expected to generate the value or Timeout, if it fails to generate a value (for what ever reason) it's expected to to Retry: 1: public class FooService : IFooService 2: { 3: private readonly IBarService _barService; 4: private r...