The blog of Eric Sibly; focusing on mountain biking, .NET development for the Desktop, Smartphone and PocketPC.

Tuesday, June 21, 2005

ItemId unique identifier…

In Windows Mobile 5.0 we have the ItemId class that is used to uniquely identify PIM and Messaging items. This class has a constructor that takes an integer, which is the unique code of the identifier which will load the appropriate PIM object. Nice :-)

Let’s say within my application I use the ChooseContactDialog class to select a Contact. (This is a really nice feature of Windows Mobile 5.0 and the corresponding Contact.ShowDialog and alike provide the means to write some really cool integrated applications with the PIM.)

Now I want to save the selected Contact for future reference, maybe store a reference in SQL CE. To do this we should save the unique identifier for the contact which as we know is represented by the ItemId. The only thing is that there is no publicly accessible property to get access to this integer value – which you would think would be perfectly logical?!?

All is not completely lost as I did manage to get access to this value via a hack; but it means outputting it as a string and converting back to an integer – ew! Code as follows:

// Show contact chooser.
ChooseContactDialog ccd = new ChooseContactDialog();
ccd.ShowDialog();

// Get the selected contact.
string text = ccd.SelectedContact.ItemId.ToString();
int id = Convert.ToInt32(text);

// Show the contact using the identifier.
Contact c = new Contact(new ItemId(id));
c.ShowDialog();

Monday, June 20, 2005

A quick joke...

Two blondes walk into a building... you'd think at least one of them would have seen it ;-)

Campbell wins US Open...

Congratulations to New Zealand's Michael Campbell who won the 105th US Open beating a charging Tiger Woods.

I have always been a fan of Campbell since the very early days having watched him play at Manor Park Golf Club in Wellington. In my early teens I used to attend holiday coaching sessions and Campbell was there – he was "WAY" better than the rest of us. Of the many good New Zealand players he was the guy who had that something extra, and it was only a matter of time before he won the big one; he had come close at a British Open a few years back.

Thursday, June 16, 2005

The great Aussie bank robbers...

NOT! This is so funny, how stupid can some people be? Two Australians are currently pleading guilty for armed robbery in the US. Here is the best bit (see here for the whole story):

Firstly, the robbers' accents were a give away.

The alleged robbers also wore name tags from a sports store they worked at in Vail.

Vail police knew of Prince and Carroll after arresting them on January 4 for shooting windows with BB guns. Similar guns were used in the hold-up.

Herbie: Fully Loaded...

Last night the family went to see the new Herbie: Fully Loaded movie at an advanced screening (Caleb's class were given free tickets - nice one!). It was actually a pretty good movie, a good clean family movie; we all really enjoyed it - very funny. Some of it was a little far fetched, but what do you expect? After all, it is about a car that is alive ;-)

The weird thing was because it was an advanced screening, has not yet been released in the US yet, there was heightened theatre security?!? On entering you had to hand over your mobile phones and any other recording devices; they even had hand held metal detectors like at an airport to make sure none were smuggled in. All a bit of a w*** quite frankly; I don’t think that Herbie is that much of a big deal to warrant all of the fussing.

Monday, June 13, 2005

All Blacks just scrape in...

NOT! They played Fiji and kicked their arse 91-0. I feel sorry for the Island nations as they really do not have much of a chance, as the really talented players end up migrating to NZ and playing for the All Blacks. They have little money to attract and keep their players - there will surely come a time when they just won't play us as it is just too lop-sided.

Also, the NZ Maori's had a great win against the touring Lions. Hopefully, they will provide some decent opposition to the All Blacks.

Friday, June 10, 2005

A few good (performance) men...

Rico Mariani of Microsoft posts a very clever parody based on the famous "you can't handle the truth" scene from A Few Good Men - bloody funny!

He is the main excerpt:

Developer: Why was my feature cut?

Performance Czar: You want answers?

Developer: I think I'm entitled.

Performance Czar: You want answers?

Developer: I want the truth!

Performance Czar: You can't handle the truth.

Son, we run on a processor that often stalls, and those stalls have to be prevented so everything runs. Whose gonna do it? You? Your froofy team?

I have a greater responsibility than you could possibly fathom. You weep for your feature, and you curse the performance team. You have that luxury. You have the luxury of not knowing what I know. That your feature's death, while tragic, probably saved bytes. And that my existence, while grotesque and incomprehensible to you, saves bytes.

You don't want the truth because deep down in places you don't talk about at parties, you want me saving bytes, you need me saving bytes.

We use words like L2, swaps, and working set. We use these words as the backbone of a life spent defending something. You use them as a punchline.

I have neither the time nor the inclination to explain myself to a man who rises and sleeps under the blanket of the very space that I provide, then questions the manner in which I provide it. I would rather you just said "thank you," and went on your way. Otherwise, I suggest you pick up a profiler, and save some bytes. Either way, I don't give a damn what you think you are entitled to.

Thursday, June 09, 2005

Assigning a Nullable.Value is expensive...

Whilst enhancing some existing code today to support Nullable within some highly performant serialization code I noticed a doubling in the serialization times. My tests indicated that the coding resulted in a doubling of the time to perform the serialization on average, it went from 2 milliseconds to 4 per Type to serialize. This is with 25% of the fields being defined as Nullable. Not significant in the overall scheme of things within a total transaction time on the server, but certainly enough to peek my interest to investigate further.

I wrote a little console test app in an attempt to isolate the problem in case I was doing something stupid - which is quite possible ;-) I am using the latest Visual 2005 Beta 2.

The code basically boxes a DateTime/Nullable and then casts each back to the DateTime primitive using a Stopwatch to determine the total ticks. The following is the test code:

private static void PerfTestNullables()
{
PerfTestNullable();
PerfTestNullable();
PerfTestNullable();
}

private static void PerfTestNullable()
{
DateTime dateTime1 = DateTime.Now;
Nullable dateTime2 = DateTime.Now;
Nullable dateTime3 = null;

object obj = dateTime1;
DateTime dt1;
Nullable dt2;

// Test normal DateTime cast.
Stopwatch sw = new Stopwatch();
sw.Start();
for (int i = 0; i < 1000000; i++)
dt1 = (DateTime)dateTime1;

sw.Stop();
Console.WriteLine(sw.ElapsedTicks);

// Test generics cast, HasValue and assignment
sw = new Stopwatch();
sw.Start();
for (int i = 0; i < 1000000; i++)
{
dt2 = (Nullable)dateTime2;
if (dt2.HasValue)
dt1 = dt2.Value;
}

sw.Stop();
Console.WriteLine(sw.ElapsedTicks);

// Test generics cast and no value (no assignment)
sw = new Stopwatch();
sw.Start();
for (int i = 0; i < 1000000; i++)
{
dt2 = (Nullable)dateTime3;
if (dt2.HasValue)
dt1 = dt2.Value;
}

sw.Stop();
Console.WriteLine(sw.ElapsedTicks);
}

The results are as follows - I was certainly surprised by the difference - it is significant.

18212   // Test normal DateTime cast.
110856 // Test generics cast, HasValue and assignment
37330 // Test generics cast and no value (no assignment)

18047 // Test normal DateTime cast.
107263 // Test generics cast, HasValue and assignment
44612 // Test generics cast and no value (no assignment)

24410 // Test normal DateTime cast.
108138 // Test generics cast, HasValue and assignment
51104 // Test generics cast and no value (no assignment)

The following MSDN bug has been created.

Wednesday, June 08, 2005

Annual sports day - Caleb wins...

Bardon State School had their annual sports day today, with the kids competing for their allocated Houses - Jubilee (the boys), Bowman and Simpson.

Caleb started the day well by winning the Year 1 (5-6 yrs) Cross Country race; a bit of a surprise as we thought of him as more of a sprinter. He didn't fair so well in the 100m, just missing out on the final by coming 3rd in his heat - still a top effort! His Year 1 relay team also won.

Kyle did really well as he is not reknowned for his running. He was 5th in the Year 3 (7-8 yrs) Cross Country - a fantastic effort! And the 100 and 200m, well lets just say that he did his best :-) His Year 3 relay team also won.

Monday, June 06, 2005

Newsgator re-enabled in Help/About...

The other day I ran into issue that Newsgator was no longer running in Outlook and I couldn't figure out why. I repaired Newsgator using the installer and still no joy, I then tried a bunch of other unsuccessful attempts of manully re-adding the add-in :-(

Finally found the following article on how to fix.

Now what sort of weirdo at Microsoft decided that the logical place to discover the disabled add-ins was in the "Help/About" dialog under "Disabled Items" - what the? Surely when hunting in the Add-in manager there should have been a means to discover here - or is that just too logical? Who the hell goes to "Help/About" to discover and fix issues?

Thursday, June 02, 2005

Surgery success...

I mentioned the other day that my Dad had gone into hospital because of fibrillations of the heart. Well, on Tuesday they inserted his brand spanking new defibrillator and he was up and walking around the next day so they discharged him - amazing! They are now staying with us until they fly back to NZ on Saturday. Stink holiday; better luck next time I suppose ;-)