Nice looking WinForms controls from telerik

telerik (excellent asp.net controls) entered WinForms controls market a bit late, but with an interesting innovation: their r.a.d. controls for WinForms are highly skineable (or themeable if you wish) and animatable in a WPFish way. Not that surprisingly they call their system telerik Presentation Framework (TPF). They have a nice hierarchy of elements including value storing in a bag instead to local fields. Another positive feature is that all the controls are built from small atomic elements so the control look is customized at this element level and doesn't need specific customization. Which is very good for you if you are extending TPF. telerik also provides a Theme Builder utility for your convenience, so you can build new themes or customize existing ones with few clicks here and there.

Even though TPF is pushing the limits of GDI(+) and telerik has done good job, it can't compete with WPF but it comes close as much GDI(+) allows. IOW it can be a good choice whether you are not willing to go with .net 3.0 for some reason (there are some reasons, among them the current lack of 3rd party market, customer doesn't want to install WPF, your application has to run on Windows 2000 or even worse, on Windows 98SE...) but you want or need similar UI. Perhaps the transition to telerik WPF stuff, which will eventually come someday, will be fairly easy due to similar architecture.

On the negative side, what is missing are heavyweight controls like grid, treelist and stuff like that to have a consistent looking application - you are forced to combine with non-TPF controls and loose consistency.

How much time and manpower did Microsoft take to implement the Off menu?

You will never guess, don't even try it. Here is the article that made Frans Bauma sad. Very very educational, highly recommended read (assuming that it is correctly written).

But what's even funnier is that none of those Sleep/Hibernate/Hybrid Sleep options work for my pretty decent new computer. It goes to sleep/hibernate/hybrid sleep but then immediately returns to normal functional state for no apparent reason (anybody knows how to pinpoint the source of the problem?). I guess they would have to duplicate the effort spent on sleep feature.

Please, don't abuse try/catch

You should have heard from experienced developers that you shouldn't abuse try/catch to handle a situation that is predictable and easily handled with an if statement. Even guys at [MS] preach this approach.

Take a look at this piece of code:

string fileName = "somefile.xml"; bool notFound; try { FileStream fs = File.Open(fileName, FileMode.Open); // do something } catch (FileNotFoundException) { notFound = true; }

While this method produces correct output (notFound=true) when file isn't found there are at least two problems in there:

  1. Method is slower when file isn't found (because of throwing exception overhead). This is just a small overhead.
  2. What's more annoying is that if you have Debugger/Exceptions... settings set to intercept all exceptions (shown in picture below) you will catch such exceptions even when there is nothing wrong with the code.

The reason why I am writting this post is that I get such an exception when creating an instance of IsolatedStorageFileStream class. Visual Studio correctly stopped on instance creation telling me that an exception of type FileNotFoundException occured.At first I was a bit puzzled why would I get FileNotFoundException when I was passing FileMode.Create flag. Doesn't make sense, right? Wrong. IsolatedStorageFileStream constructor internally implements similar (not same) code described above. It uses a handled exception for checking whether file exists even when using FileMode.Create!

Instead the code above could be rewritten as:

string fileName = "somefile.xml"; bool notFound; if (File.Exists(fileName) { FileStream fs = File.Open(fileName, FileMode.Open); // do something } else notFound = true;

This approach is more elegant, readable, faster and it doesn't throw anything on predictable problems. I guess [MS] guys could clean up a bit .net library.

UPDATE (gorazd pointed that there is a possibility that file disappears between File.Exists and File.Open - while I thought of this when I was writing this post I forgot to include it in the code). So, here is an improved v2:

string fileName = "somefile.xml"; bool notFound; if (File.Exists(fileName)) { try { FileStream fs = File.Open(fileName, FileMode.Open); // do something } catch (FileNotFoundException) { notFound = true; } } else notFound = true;

UPDATE: The good news is this behavior is a must only in Visual Studio 2003. Not because of a code change. No, there is actually an option to disable catching non-my-code exceptions. The option is turned on by default. So, here it is:

You'll find it in Tools/Options... Unfortunatelly that doesn't help if you are stuck in a Visual Studio 2003 world.

When Murphy kicks in on presentation

I had my worst presentation so far today. While Matjaž delivered his usual good talk I created a mess but it wasn't my fault. At least not a huge part of it. The plan was to show how a get-process cmdlet is quickly and easily built with Visual Studio 2005 and to show a simple SqlServerDBProvider in action.

To save time I fired up Visual Studio 2005 before presentation (it talks quite some seconds on my laptop), opened "Add Reference..." message box (it takes time to enumerate all assemblies if they aren't in cache), closed dialog and waited for my turn. After Matjaž introduced Power Shell I started creating get-proc cmdlet. I created a new class library process and renamed default Class1 class to GetProcCmdlet. So far so good. Next I typed : and a letter C (inheriting from Cmdlet class). Here the disaster struck. Visual Studio 2005 has frozen for some reason. To make it worse I was unable to kill it. To make it worse the second Visual Studio 2005 instance has frozen at same point, too. To make it worse I was unable to kill this instance, too. To make it worse I had to restart (hardware reset) Windows XP SP2. To make it worse it takes quite a lot time for Windows XP SP2 to boot up after so cruel restart. And when I finally managed to start up Visual Studio 2005 again I lost a couple of minutes in Add References... dialog. After this the demo went smoothly until the time for second demo came. Brutal restart affected the other demo somehow, too. And I lost again quite a lot time repairing and restarting second demo. At least Matjaž had some fun and an opportunity to poke jokes on developers.

Oh well, an experience to learn from.

You have to license Ribbon UI on your applications

This one might come as a surprise to developers: If you use [MS] like Ribbon UI (Word 2007, Excel 2007) in your application you have to get a license from [MS] in order to legally use it. And it doesn't matter if you buy a ribbon component from 3rd party vendor ([DevEx] makes very nice one) - you still have to get a license from [MS].

Quote from the link above:

"To that end, Microsoft has created a royalty-free licensing program that will enable developers to build applications that have the look and feel of the new 2007 Office system applications. The new program will license elements of the new UI to software developers and component vendors on a royalty-free basis."

[MS] has done something similar if you wanted to play with Office native file format - you have to sign an agreement that you won't use that knowledge in a competiting product. Now they are extending it with requirement to follow their UI guideliness, too. So we. developers, might be constrained in extending Ribbon functionality.

I wonder how much is this a precedence. Imagine that you are building a complex application and you have to obtain licenses for every part of it that is similar to something somebody already done. At least it is free for now but this might change in the future...

I'll be co-presenting Windows Power Shell at SLOWUG

Tomorrow (Wednesday) I'll be co-presenting Windows Power Shell with Matjaž Ladava (MS dude) at Slovene Windows Users Group (SLOWUG). It will be quite a challenge talking about cmdlet development to a group of admins. I don't plan die-hard lessons, just a quick overview on how cmdlets and providers are built so they get an impression of what's behind all thos verb-nouns things and perhaps built easier ones on they own.

Red-gate's SQL Compare

Recently I was facing this problem: I am developing an asp.net 2.0/remoting/winforms application which stores data in Sql Server 2005. From time to time I publish my application and its database to the public for testing purposes. The project is under development plus I don't create database at the beginning and never change it (because of various reasons). Instead I add metadata and change database structure here and there. No problems so far but when I need to publish a new version, I have a problem if I want to keep public date and not just overwrite them with new database. What were my options so far:

  1. carefully record each database modification and store SQL DDL statements. Run all these statements on public database at publish time. This approach works but it is tedious
  2. create new blank database with latest structure and somehow import data from public database. Substitute public database with this new one. Again, tedious.

Fortunately Red-gate comes to help with its Sql Compare product. It is able to keep database structures in sync, or better, at publish time I just say to SQL Compare that my target database structure (public one) has to look like the development one. SQL Compare compares two database structures and report what's and how's changed. After this step I could just press Synchronization Wizard... button and it would synchronize the target database. Or I can check out the proposed SQL statements SQL Compare creates for me. There is also plenty of options to tweak its behaviors one wishes (i.e. you can filter out the database objects that you don't want synchronized). As a cherry on the pie there is also a command line version and a set of .net API (SQL Toolkit) that lets you do the job from your .net application (I didn't test it yet but I see its great potential).

The bottom line is that Sql Compare is a great time saver tool when you are dealing with Sql Server database synchronization.

And there is much more from Red-gate. They have full set of tools that helps you manage Sql Server beast, the latest one and fresh from the owen being Sql Refactor. That's right, Sql Server refactoring tool - no more hassles when you need to rename an object and then search for all the spots where you have to rename it. I can't wait to try this one out...

About Visual Studio 2003 on Vista

A while ago Somasegar's blog post about MS not supporting Visual Studio 2003 on Windows Vista caused quite a stir in community. A lot of people were very concerned about this issue.

A note at this point: .net 1.1 and newer will be fully supported. It is just the Visual Studio that has problems. While they are putting all their effort in Visual Studio 2005 (through Service Pack 1 - it will be required - and there might still be some minor issues) and Visual Basic 6 (apparently still alive) they are leaving Visual Studio 2003 behind. The suggestion here is to use virtual machine to run Visual Studio 2003 on some other OS within this virtual environment. However, this is not an ideal solution for several reasons - the most important being that not everything runs in virtual machine environment, such as DirectX applications. The other almost equally important is slowness of virtual machines.

Back to the cause of the problems. Most of the problems are caused by Vista User Account Control (UAC) which is very aggressive in protecting the OS from various threats. And the side effect is that it nukes debuggers. In other words, you can run Visual Studio 2003 but you can't debug (remember old times, when we were putting a ton of "Output" methods in code instead of debugging).

Here are the good and the bad news: It is possible to run Visual Studio 2003 including debugger (at least in normal debugging situations - debugging WinForms, Console applications - I didn't tested others) in Vista but it comes with a price. You have to turn off UAC (you can do it by running msconfig utility) and switching on/off UAC requires a machine restart. Yep, I have turned it off because I need Visual Studio 2003 for DirectX managed applications. I guess I won't be using UAC for a while.

In my opinion (and in opinion of many others) MS' decision to support VB6 instead of VS2003 remains very questionable.

UPDATE (23.12.2006): Dan posted a comment with link to "what's not working in vista and how to workaround it".