Software Dictators

If you run any version of Windows with auto-update enabled then you are familiar with this little box:

Use it as reminder of something you should never do.

What’s wrong it? Computer will close whatever you had open and reboot and unless you are at your machine to see this dialog your open apps are gone. Even if you see it your options are to Postpone or Restart right now. In essence you have no choice. Your computer is taken over by software dictator.

I have backup scheduled in the middle of the night. Of course, the Windows updates get installed when computer wakes up from sleep to perform backup, and since that function in Windows does not anticipate that there might be no human seeing Windows Update message, it reboots the machine and interrupts the backup in the middle. Many times I have lost all state I had in open apps until I had this turned off.

The only remotely acceptable option for that Windows Update dialog would be if your desktop and all open apps are returned to exact same state as before reboot. But, they are not.

Contrast that with how Mac OS X handles the OS updates. It does not show any dialog whatsoever. It does not stop your work-flow. The Update icon in dock-bar starts bouncing to let you know something is up and when you click it, you see this (note that icon in dock stops bouncing and just sits there after certain time interval):

And you are free to ignore it as much as you want. You can keep it open for weeks until you decide that updates can be installed and machine rebooted. This design is not taking over your machine and breaking your work-flow to install an update which in no way is what you need right that moment.

On Windows, its race to disarm the reboot ticking bomb.

Software should never be designed so it forces the user to do anything out of the context of his current work-flow.What I mean by that is following; Showing Yes/No/Cancel message box that asks user to save data when application is being closed is in context. It is direct response to user action. Showing Software Update dialog when an application is started is completely unacceptable since it is not what user wants to do. It is not in context of his intent.

When you are not in control of your machine you gets frustrated. There is one more decision to make, one more interruption to take which drives all of us nuts. And because of that we label software and even whole operating systems as hard to use, frustrating and just not pleasant.

This design point is easily overlooked. I’ve made more mistakes like this than I can count. But its contribution to pleasing, easy to use software is huge. Keep it in mind.

Tagged with:

WPF Dependency properties have an interesting flag that you can specify when registering property:

Specifying this flag allows property value to propagate through the parent tree. That means you can have property that will have its value synced with the parent (does not have to be immediate parent) completely automatically. There is small performance penalty for this of course, but for certain usage scenarios it is very useful.

Using this is not that straight forward since there are some rules that need to be followed to implement property with inheritable values. Here they are:

  • On parent, dependency property must be defined as attached property. You can still declare property getter/setter, but property must be attached. Here is simple declaration:
public static readonly DependencyProperty InheritedValueProperty =
   typeof(int), typeof(MyClass), new FrameworkPropertyMetadata(0, 
public static int GetInheritedValue(DependencyObject target)
   return (int)target.GetValue(InheritedValueProperty);
public static void SetInheritedValue(DependencyObject target, int value)
   target.SetValue(InheritedValueProperty, value);
public int InheritedValue
      return GetTimeSlotDuration(this);
      SetTimeSlotDuration(this, value);

  • Child objects would define their instance of the property with inherited value using AddOwner. Following is the code that goes into say MyChildClass sample class:
public static readonly DependencyProperty InheritedValueProperty;
public int InheritedValue
      return (int)GetValue(InheritedValueProperty);
      SetValue(InheritedValueProperty, value);
static MyChildClass()
   InheritedValueProperty = MyClass.InheritedValueProperty.AddOwner(typeof(MyChildClass),
      new FrameworkPropertyMetadata(0, FrameworkPropertyMetadataOptions.Inherits));

Note that property is in child class declared as standard dependency property and that it specifies Inherit in meta-data options.

With setup like this now when MyChildClass in parented to MyClass visually or logically they will share the same property value automatically.

Tagged with:

WPF Tip: Label Word Wrap

The WPF Label control is powerful, but if you simply set Content property to a string, it will not wrap on multiple lines. What to do? Use TextBlock:

<Label >

<TextBlock TextWrapping=”Wrap”>

Lorem ipsum dolor sit amet, consectetur adipiscing elit. Morbi a est libero. Nulla quis purus in est suscipit fringilla. Aliquam.



Notice TextWrapping property on TextBlock which specifies that text should wrap.

And if you need to use access key in label then wrap text into the AccessText instead like so:

<Label >

<AccessText TextWrapping=”Wrap”>

_Lorem ipsum dolor sit amet, consectetur adipiscing elit.



Tagged with:

I posted before on How to Install Windows Vista or Windows 7 from USB Flash Drive which uses manual command line method to transfer your CD/DVD installs onto the bootable USB stick. I just used that other day to build bootable USB stick with Windows 7 RTM and it works great.

However, I just found about free WinToFlash utility which automates that process. So, if you are in hurry to build that bootable USB stick with Windows install it might come handy:

Tagged with:


No, not wheel spinners! You’ve seen these animated gif’s used in AJAX apps to indicate that an operation of undetermined duration which might or might not complete is in progress. Here:


If you are after these here is good web site to automagically create them.

And you can use them in desktop apps too. I used animated gif in TweetPow while tweets are being loaded, because you know, that perfectly defines an operation of undetermined duration which might or might not complete…

Anyway, for desktop apps, simply add them to the PictureBox and voila, they spin.

Tagged with:

I’ve been often asked how to improve performance of WinForms apps so here is the list of my top suggestions and further reading recommendations on how to speed up your Windows Forms applications:

  1. Reduce modules loaded by your application to increase start-up time. Remove all references from your project that are not used. Click here to read MSDN article on that on other techniques.
  2. Pre-compile your assemblies using NGEN when appropriate to decrease start-up time. Click here to read my short post with guidelines on when to consider doing this.
  3. Use native C++ Splash Screen that shows up immediately when your application is started. This will make your application appear to load faster. Click here to read and download C++ project with native splash screen. Native splash screens have such small memory footprint that they appear immediately.
  4. Don’t set BackColor=Transparent on your controls. Transparent color support in Windows Forms is terribly inefficient since it is not real transparency. Whenever you set BackColor=Transparent you incur additional Paint call on the parent control. As part of child control rendering, child control will first direct parent control to paint itself on it then child control will paint over that so it appears it is transparent. And this is repeated for every single control that has transparent background. Couple that with the next point and you have real slow-down.
  5. Reduce usage of gradients. Gradients whether linear or radial especially on large surfaces of screen are slow. I know they look good, but use solid colors whenever possible and you will see much better rendering performance. Especially on large panels.
  6. Reduce code in Form Load event. Use BackgroundWorker to offload work onto the different thread so your UI can load faster and feel snappier while you do other work.
  7. Delay Control Creation. Creating and populating controls takes lot of time, so if you can, delay it or do it on demand. For example, you can avoid creating controls on all pages of Tab Control right away and do so in either Appllication.Idle event or when that tab is selected from SelectedTabChanged event.
  8. Set DataSource last. When using data-binding set DataSource property last. If you set it before you set ValueMember or DisplayMemeber properties for bound controls, the data source will be re-queried to populate control each time these properties are set.
  9. Use SuspendLayout and ResumeLayout on parent controls and form to optimize layout changes. Bounds, Size, Location, Visible, and Text for AutoSize controls causes the layout changes. Note that you should call these methods when performing multiple layout changes and always on parent control of the controls that you are changing layout for.
  10. Use BeginUpdate and EndUpdate when adding multiple items to trees, grids and other controls that support this.
  11. Call Dispose() method on your forms once you are done with them. Most of the time developers forget to call Dispose() method on form they’ve shown using ShowDialog(). Make sure you always dispose your forms and controls to free up memory. Use handy using statement.
  12. Dispose() your graphic resources. If you are performing any custom drawing make sure you explicitly dispose your Pen, Brush, Image and other graphic resources once you are done with them. Using statement is good for this as well.

Do you have more tips for speeding up the WinForms application? Please share them in comments below.

Also check out the 2 Things You Can Do Today To Improve User Interface In Your Applications post for helpful UI tips.

Tagged with:

How To Debug WPF Binding

One of the probably most common things you do in WPF is specify Bindings. But how do you debug them?

In WPF 3.5 there is new diagnostics that you can turn on that will output detailed binding messages to the Output window. Immensely helpful when you are trying to debug why your binding does not work.

To set it up first add diagnostics to your namespace:

<Window x:Class=”Tester.Window2″


Then enable it on per-binding instance as such:

ItemsSource=”{Binding Path=PaneItems, diag:PresentationTraceSources.TraceLevel=High}”

Now when you run your app watch Output window for clues on why binding is failing.

Hope this helps save your sanity while debugging bindings as much as it does mine 🙂

Tagged with:

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

© 2009 Denis Basaric: DevComponents Blog