August 2007 Entries


Good Quote

My project manager had a qood quote about impossible deadlines I thought I would share. "you can not make a baby with 9 women in one month" Very suiting quote for lots of projects I have worked on.

Setting A Label From A Different Thread

We have the scenario where multiple labels values are being set from a different thread. When this happens an exception is thrown as labels (and most other controls) are not thread safe. To get around this you can have the hosting form do a BeginInvoke to queue the message to the proper thread (I think that internally it does a SendMessage to the form to do the actual work). To do this I create a delegate to a method that sets the labels value:Private Delegate Sub SetLabelDelegate(ByVal value As String, ByVal label As Label)Then I create the method:   Private Sub SetLabel(ByVal value...

Things I Learned About FoxPro

On my current project I have to connect to a legacy FoxPro2 database. I know nothing about FoxPro but it was fairly easy to connect to and use in ADO.NET. I had a few stumbling points that I thought I would share in case you have to connect to one. 1. Named parameters are not used by oledb/odbc commands. They are ordinal and represented by question marks:command.commandText = "insert into users (firstName, lastName) values (?, ?)"The commands then need to be added in the correct order:command.parameters.add("@firstName", customer.firstName) command.parameters.add("@lastName", customer.lastName) I know I show the parameters as named in the add() method...

Extension Methods For Casting

I have not played much with orcas or .NET 3.5 but had an interesting idea so had to crack and get it up and running. One thing I have not liked is having to cast/parse types as it leads to harder to read code in some situations . i.e.:int myInt = int.Parse(((customer)value).SocialInsuranceNumber)ordim myInt as integer = integer.Parse(ctype(value, customer).SocialInsuranceNumber) So playing around with extension methods I got code like this that is a bit more fluent:int myInt = value.CastTo<customer>().SocialInsuranceNumber.Parse<int>();I find this a lot more readable. Here is the code: public static class CastExtension    {        public static T CastTo<T>(this object value)        {            if (value...

Datasets Vs. DTOs

On my current contract the powers that be feel that datasets are the way to go for everything and it has become their new standard. While I feel that datasets are powerful and useful in some (rare) situations I feel that this is a bad idea. I did not find much on the comparison between the two techniques so I thought I would write one up. Please don't take this as an attack on datasets typed or untyped). I am just pointing out why I avoid them for most apps. I appreciate any contributions to this post either for or against...