Skip to main content

Posts

Showing posts from November, 2014

UI freezing when CPU hits 100% constantly

I've been working with a team where I've been putting a WPF UI over a set of implementations of a custom interface. Each implementation is a long running process which is handled in standard manner by creating an asynchronous Task<T> and displaying the results from the continuation. The standard CPU utilisation for the majority of the interface implementations is shown below - this represent the ideal, not hogging the CPU's and behaving like a good citizen... Where as one implementation has the following CPU utilisation - all logical processors max'ed out. The app becomes unresponsive, the UI starts to stutter and freeze all because the dispatcher (UI) thread is not being scheduled frequently enough - white screen of death (WSoD). It's not only this app it starts to affect but all other apps running. Hopefully the difference between the majority and this particular instance is obvious - the majority are single-threaded long running processes and t

Modelling units of measure

I've been looking at writing an exercise app, and this would require some kind of units of measure for distance (as well as time). I could use an enum to represent the different types of units - metres, kilometres, yards, miles etc. But this seems to be lacking from the point of view of converting between the different types - I would need a class to represent the conversions. What I want is a more integrated approach - the use of static read-only properties. What I want to be able to do is best described by the following test: The Measurement struct is very simple, a couple of properties - Amount & Unit and a ConvertTo method: As you can see in the ConvertTo method the Unit class owns the conversions - it is more than just a simple Enum - it has behaviour, how to convert between the different units of measure. So how are the units defined? A Unit instance is exposed as a read-only static property on a static Units class: What makes this approach interesting