Monday, 30 June 2008

Velocity First Look

Normally I avoid CTPs like the plague, but I'm interested enough in this one that I installed the first CTP of the Velocity caching engine over the weekend.

Haven't tried coding against it yet but I had a bit of a play with the command-line admin console and read some of the help.

The most obvious missing element right now is a CacheDependency object (+ subclasses viz. SqlCacheDependency) - I've been trying to think of a way to chain this and the ASP.NET Cache together to retain the ability to have dependencies butI haven't come up with one yet :-(

I'm intrigued by the idea that you can lock and unlock cached objects, though since in the finished version it should run across multiple servers I guess this is a way to avoid race conditions.

Edit: Something else missing I just discovered is that the service out of the box doesn't survive a restart i.e. you have to go into the Admin console and issue a new 'START CLUSTER' command. I've now marked the Windows service as 'Automatic', not 'Manual'.

Thursday, 26 June 2008


Well that was disappointing.

I installed the MS OpenXML SDK this morning (from after reading about it in Woody's Office Watch. I was hoping it would have classes to let you generate Office documents on a server without having Office itself installed (been bitten by this before). Unfortunately, it doesn't. Or at least not that I can see from looking at the Class Reference in the Help.

BTW Microsoft, what's with shipping the help file as a CHM? I thought all DevDiv products now shipped with MSDN-style help (don't know the technical name for that one). The helpfile is also slightly unpolished - all the 'How Do I' topics are suffixed with '... using the OpenXML API' - isn't that slightly obvious in the OpenXML API Help!

Wednesday, 25 June 2008

Editing Collections

If you try to edit a collection using, say, a For...Each loop e.g.

For Each item in Collection.items
Next item

it's quite feasible to get an error which says you can't edit the collection you're iterating over while you're iterating over it. Which kind of makes sense.

The trick to doing it is to iterate over it backwards e.g.
Dim i As Integer
For i = Collection.Count To 0 Step -1
item = Collection.Item(i)
Next i

This way, you remove the items from the end of the collection, not the middle, which allows the .NET Runtime to keep track of the collection correctly.

(This might seem obvious to some but it held up some coding for me for about a month until a colleague made chance remark about it!)

Tuesday, 24 June 2008

CancelButtons and Visual Inheritance

I started writing a new WinForms app yesterday, which is going to be a Wizard. I created a base form to inherit from so that all forms would be the same size, have Next & Previous buttons etc. I also added a button called CancelButton, which has to be marked as Shadows so it doesn't screw up the CancelButton property of the form itself.
However when I tried to create the first form subclassing my base form, I got an 'Ambiguous match found' error in the Visual Studio designer. Couldn't find any obvious solution from Googling (partly why I'm blogging it here), but the solution was to rename the button on the base form to 'MyCancelButton' (or, I suspect, anything but CancelButton). It seems that even if my CancelButton was marked as Shadows, the VB.NET compiler isn't quite cute enough to figure out what's supposed to happen.