Null-coalescing Operator

In my code there is lot of checks like this:

...
if (text == null) {
    text = "Some default value";
}

With C# this line can be written as:

...
text = text ?? "Some default value";

This will definitely make code shorter and while I use strings here, it is not limited to them. Any object will do.

Most of time I find this syntax less readable than first example. Part is probably because I am not used to it and part is definitely because of those question marks (??). Somehow they make me uneasy.

However, it is great help in your database layer when you need to get some value out of nullable type:

int count = dbCount ?? 0;

Once you need to set ten fields to defaults if their value is null, you learn to appreciate it.

Password Hint

Illustration

During installation of Windows 7 there is one point where you get asked for password. Thing that did surprise me is the fact that it requires password hint to be filled. While I do see use and benefit of it, especially for accounts that are used only occasionally, I cannot understand why that hint was made required parameter.

Even worse, if you chose not to have password and add it only later, password hint is not mandatory any more. Seems like a little inconsistency to me.

Shutdown Event Tracker

I have dual-boot installation of Windows Server 2008 R2 in order to play with Hyper-V. I run it only occasionally and thus I am quite annoyed with shutdown event tracker. While I can understand benefits in normal scenarios, it is quite unnecessary for test installations.

Problem here is that there is no obvious check-box that would disable it. However, Group policy comes to rescue.

Open Start menu and select Run (or hit ) and type gpedit.msc. Press OK and that should open Local group policy.

Go to “Computer Configuration” > “Administrative Templates” > “System” and on right side you should see “Display Shutdown Event Tracker”. It’s common state is “Not configured”. That configuration will cause server OS (Windows Server 2008 R2) to display it while client OS (Windows 7) will not.

Setting this value to “Disabled” removes this annoyance.

Creating Location-Aware Applications for Windows Mobile 6.5 Devices

Illustration

I gave presentation at Mobility Day 2009. Since I was traveling from Berlin this morning (started at 5:00) I was quite tired, but presentation went mostly fine.

As promised, here is code download:

There are few prerequisites:

  1. Your emulator needs to have Internet connection.
  2. You need to have GPS support in Windows Mobile emulator. FakeGPS will do.
  3. Do not forget to put your Bing Maps user ID and password in Program.cs. If you do not have developer account, you will need to request it.

P.S. As a bonus, download also contains desktop application that speaks with Bing Maps. It is much faster to test various setting this way.

P.P.S. NMEA stands for National Marine Electronics Association and not, as I said, “Nautical something”. :)

Programming With Remote Assistance

Illustration

I needed to do some programming on other PC and Remote Desktop was obvious solution. However, since it wasn’t my computer, I felt uneasy doing something while other person could see it. Next best choice was Remote Assistance.

If you intend to write code via Remote Assistance be aware of some issues:

1. Mailing invitation doesn’t work every time.

For some reason, mail invitation works in aproximatelly 50% of cases. I could blame corporate firewalls and proxies, but it seems to me that, if you are going to have such feature, you need to anticipate those problems.

2. You need to work in window.

For some reason, you cannot go into full screen in order to see other side. You will stay in window and, since there is chat window and some status around, destination needs to be a lot smaller. My home resolution was 1280x1024 and I could manage only 800x600 on other side. Second solution would be to scale window, but it is very hard to program if all you see is bunch of pixels.

3. Escape key is used for disconnect

Every time you hit escape key, you will disconnect remote control mode. In order to continue working other side will need to approve you again. And again. And again. If you are used to close windows with escape key (e.g. Intellisense windows), you will disconnect a lot.

Reasoning behind that “feature” was understandable. Allow user to disconnect at any time if he/she sees suspicious behaviour of repair-man. However, that does not explain why it disconnects when remote side hits escape button also. I doubt that there is scenario when remote side wants quick way out - especially mapped to escape key.

I did solve it after ten or more disconnects. I took screw driver and popped it out.

Conclusion

While I cannot say that I enjoyed this much, it was enough to get job done. I assume that with this solution it is as good as it will get.