Creative Commons License



Entries from June 1, 2008 - June 30, 2008


Your windows service started and stopped

The name-of-your services on Local Computer started and stopped. Some services stop automatically if they have no work to do, for example, the Performance Logs and Alerts service.

I had fun with this one for a bit.  Developing Windows Service is one of those "I rarely do this" activities.  So when I got one of these errors when I start my service, immediately I switch into "Ah I must have forgotten something" mode.

  • May be the process started and didn't do anything and finished
  • May be the timer didn't go off
  • Perhaps I need to spawn a thread to listen / sleep

I couldn't attach a debugger to the service given that it doesn't stay running.  So that limited my options a bit.

Turns out, the "informational message" was pretty misleading, I had the following in my event log.

Service cannot be started. System.NullReferenceException: Object reference not set to an instance of an object.
   at MyService.MyService.OnStart(String[] args)
   at System.ServiceProcess.ServiceBase.ServiceQueuedMainCallback(Object state)


Fixed that error, and the service starts successfully.


Being a consultant is:

  • Walking on a tight rope
  • Crazy business requirements people on one side
  • Poor internal dev teams (the maintenance guys) on the other side
    • I try to be nice to my fellow devs, they deserve a great system to work with, not a hacked up thing
  • Dual-Whip-wielding project managers chasing you from behind (think: Balrog)
    • (Though to be honest, they are probably chased by stake holders)
  • And if your project is slightly short on money, you might as well dose the whole circus in petrol and set on it on fire.


Mark: When you charge a fortune

Mark: The clients expect a miracle

John: So we are "miracle workers"

Mark: Pretty much


Client: We have a situation here

Client: One miracle worker may not be enough

Client: We need a team of Moses, to part the Atlantic ocean, cause this thing is sinking pretty fast


There are good consultants and great consultants.

  • There are crap ones - those that talk a lot and never get anything done.  To me these people should stop dirtying our work and go find something else to do - they give consultants a bad name.
  • There are good ones - those that gets things done but are too expensive.
  • I don't defend the cost of consultants - the service and the skills are what's being paid for.  But I think a great consultant is one that gets things done, and simultaneously manages the client's expectations appropriately.


A consultant (especially an expensive one) is a secret weapon used (usually by newly-appointed upper management) to wedge open layers of old office politics to introduce change.

It is often excruciating for the consultant.

A consultant has to preach new technology, methodologies and win converts.

People do not like change.  They will resist change.

Sometimes they will threaten to leave, and blame it on the consultants.

Ultimately, the company will realize the changes were for the better, but the consultant is never around by then to see the benefits come to fruition.


A process takes an internal dev guy 5 days to do.  Because he needs several permissions and find a time that's suitable for everyone involved to have a meeting.

It usually takes an external consultant 2 hours to come to the same decision.  Because an expensive consultant is too expensive to keep around for 5 days.  Management will move mountains, switch appointment times, even *gasp* cut short their lunch break to make a meeting.

Price tag is everything.


Quick tip: Initialising Dictionary inline

var dictionary = new Dictionary<string, string>
{ "key1", "value1" },
{ "key2", "value2" },
{ "key3", "value3" },

var list = new List<string>

You might notice that I like to leave the comma behind the last element in my inline initializers - this is actually unnecessary.  But having it there means that I can copy/paste entire lines and move them around without worrying about missing comma right at the end.

For example, this is valid code:

var list = new List<string>
But if I had to swap the order of the elements and end up with this code, this is not valid.
var list = new List<string>


Generic EventArgs implementation (but isn't really all that useful)

public class EventArgs<T> : EventArgs
private T t;
public EventArgs(T t)
this.t = t;

public T Value
get { return t; }
set { t = value; }

To use this class:

public EventHandler<EventArgs<String>> Notification;

protected void OnNotification(string message)
var handler = Notification;
if (handler != null)
handler(this, new EventArgs<String>(message));

While this code is all nice and dandy, I wonder if it's all that useful.  One of the things with custom event args is that they may grow over time, and this implementation doesn't support future scenarios that well.

My colleague Dinesh mentioned that perhaps I'll end up going down the Func<> route, ie:

EventArgs<T>, EventArgs<T, U>, EventArgs<T, U, V>

Personally I think that's a bit challenging:

If I had to add an future int property to my EventArgs<String>, changing the event to EventArgs<String, int> doesn't automatically fix the issue - as all my event hooks will now stop compiling, because EventArgs<String, int> doesn't imply it inherits from EventArgs<String>

Anyway, nice looking bit of code but I'd say not greatly useful.


A camera of the future

In the future, when you take a picture of something, the camera generates a 3D scene of it and stores it in memory.

Camera will need 2 lens to work out the distances and generate the 3D model.

Camera will record and generate the textures that we can see.

When looking at the scene from the angle that the picture was taken at, the resolution is as good as a flat-picture camera.


Missing entry: setting DateTimeFormat.ShortDatePattern across the entire ASP.NET application

This entry is about a week overdue, nonetheless I shall post it now:

In the global.asax, before page execute, do this:

protected override void PrePageExecute(Page page)
// change short date pattern of the current culture short date pattern
CultureInfo info = (CultureInfo)CultureInfo.CurrentCulture.Clone();
info.DateTimeFormat.ShortDatePattern = "dd MMM yyyy";
System.Threading.Thread.CurrentThread.CurrentCulture = info;

I'm using CompositeWeb.WebClientApplication here, if you are using vanilla ASP.NET, you can use a whole lot of different events such as BeginRequest.

Take the current culture, clone it (because the current culture is read-only).  Then set the short date pattern to something universal like "dd MMM yyyy";

This affects all instances where these are used:

datetime.ToShortDateTimeString();  // which is a concatenation of "d" and "t"

This fixes issues for our application that is used by both American (MM/dd/yyyy) and Australian (dd/MM/yyyy) audiences.

Ideally, the user would set the language setting in their browser to the appropriate locale (en-US or en-AU), but this is too hard to force upon our non-technical users and the risk of someone misreading a date is too high, so we've opted for the "dd MMM yyyy" format which everybody understands.



Updating from SilverLight 2 Beta 1 to Beta 2

Cannot specify both Name and x:Name attributes

I think this is a bug in Beta 2, where you can't set x:Name for a UserControl, and then in the parent XAML that uses the UserControl, use x:Name again.

The trick is to remove the name from the XAML for the UserControl - you can use this in the code behind anyway to self reference the user control, so the name here isn't that important.

Update project references

Old SilverLight 2 Beta 1 projects still had references to version 2.0.3xx, some manual add/remove references was required to get the project all happily working on v2.0.50727


That was all the changes I had to do.  I think I escaped lightly this time.  Oh the joy of playing with beta software.


Modelling the system



Here's a nice pretty diagram of the various components of modelling a (any) world.

In my case here, the world is a virtual world.  You would noticed quickly:

  • The strong MVC reference.  If you really don't see it, try look at the colours
  • World is made of models - which are actually no different from a business application.  The same model pretty much applies
  • SilverLight 2 Beta 2 has strong work done on the visual manager, which I think is best used to utilize for rendering the world
    • In fact, in most games, the graphics component is the main component, in my little model here, it isn't.
  • The command logic is largely work from WPF's command syntax - in a business application, this means we can wire up multiple events to the same command (aka, control-C, menu)
    • In the context of a game, it means we can offer key-bindings and the user can choose what keys he'd rather use instead of the defaults
  • The blue part is the least ironed out section of my little model here - in a pure MVC situation, perhaps the Commands should be responsible for directly making the calls to the server / modifying the game objects.
    • Should I wait for server response before making the object move?  or should I trust the client and let it start moving, and allow the server to 'validate' the client's behaviour

One final work remains in this modelling exercise:

  • Some sort of dependency-injection for making it all work in SilverLight, this way, I can work on each component one at a time and have them plug in/out
    • And unit-test separately
    • There's some good work in the AssemblyPart class
      • Not sure about security implications though

Do we really need that many controls in Silverlight?

I was digesting Scott Gutherie's blog on Silverlight 2 Beta 2

We ultimately expect to ship over a 100 controls for Silverlight.

It really made me wonder, do we really need that many different types of controls built-in with the default Silverlight installation?

Beta 2 now has around about 30+ controls, and the only one that I've noticed is missing, is the combo-drop down list control.

I'm guessing if they really plan to end up with so many controls, then perhaps they'll start by porting across all the various controls that currently WPF have and Silverlight doesn't.


Oh and some sort of Menu control


Lack of statistics for Windows

The statistics capabilities for Windows Live wetted my appetite for better statistics reporting.  Why on earth:

  • Record only up to the last 3 days
  • No user detail breakdown - where from?  Unique visitors?  Returning visitor?
  • How are people finding my blog?  Word of mouth or blog reader or searching for keywords in Google where my blog showed up?

Anyway, the lack of statistics really is beginning to be a pain in the neck, makes me feel that no matter what I do, Windows Live spaces just doesn't support me to grow my blog, unlike other service providers like Blogger or WordPress.  (Both of them easily integrates with Google Analytics).

Which drives people back to use AdWords.

Sure we hate all things Google ;-)
But where's MS's offering?