July 2004 - Posts
MyDoom caused some trouble even for Google yesterday. Some speculate the reason to be the high price on their IPO share offer, which (at $108 - $135 / share) adds up to between US$2.6 - US$3.3 billion. This price values Google at roughly US$36 billion!!!
After hours of installing and re-installing and uninstalling and re-uninstalling (and powerful swearing), I found out that the Whidbey beta does not gel with Longhorn. Did I do something wrong? Whidbey rendered my Longhorn installation completely limbless.
(I noticed that the .NET frameworks on Longhorn (build 4074) and the Whidbey demo are of different version - Longhorn has v2.0.31113, whilst Whidbey comes with v2.0.40607).
Just installed Longhorn - this is what it looks like:

Yum!! I'll tell you about my investigations right here, a little later :D
You're in a game show. There are three doors. Behind one of these is a car, and if you can guess which, the car is yours! You pick a door, but it isn't opened yet. Instead, the gameshow host opens one of the other doors, revealing that the car is *not* there. You have to make another decision: do you stay with your innitial choice, or do you switch to the remaining door?
Which would make your chances better? Does it matter?
[UPDATE] Most people think that your chances are 50-50 when only two doors remain. Wrong - see what Ian Griffiths had to say about the 'Monty Hall Problem'.
A while ago I had the user requirement that one of our WinForm apps “behave like Outlook”, in that only one instance of it ever runs per workstation. If an instance is already running, launching it a second time should bring the existing instance to the foreground.
First I thought that there would be some simple .NET framework functionality to help me accomplish this, but I ended up doing a combination of a mutex and API calling. Thanks to Armand who helped me on this.
The app's entry method tries to acquire a system-unique mutex. If the mutex isn't available, it means that another instance must be running. In this case, the process of this other instance is found, its window changed to a viewable state (it might be minimized), and then brought to the foreground - all with API calls. If the mutex can be acquired, just launch the app. The entry point looks like this:
public static void Main()
{
bool firstInstance;
Mutex mut = new Mutex(true, strSystemMutex, firstInstance);
if (firstInstance) {
try {
Application.EnableVisualStyles();
Application.Run(new frmLogin());
} catch (Exception ex) {
ExceptionManager.Publish(ex);
} finally {
mut.ReleaseMutex();
}
} else {
try {
Process[] processes = Process.GetProcessesByName(Process.GetCurrentProcess.ProcessName);
Process proc;
foreach (Process proc in processes) {
if (!proc.Id == Process.GetCurrentProcess.Id) {
WindowsHelper.ActivateWindowByHandle(UInt32.Parse(proc.MainWindowHandle.ToString()));
System.Environment.Exit(0);
}
}
} catch (Exception ex) {
ExceptionManager.Publish(ex);
}
}
}
The WindowsHelper class I use can be found over here (it does the unmanaged API calls via a managed wrapper)
[UPDATE: Fixed the broken link to the WindowsHelper class ;o)]
Ever got the following error when trying to run an MSI installer package?
80070002 - The system cannot find the file specified
Which file????? To find out, do the following:
msiexec /i someinstaller.msi /L*v msi.log
Check the msi.log file for details. Or, just as helpful, decompile the MSI with this baby :)
There's a lot of noise in the blogosphere related to the latest IE patches. Senkwe says he's about to download Firefox (I'm a Firefox user myself). But that made me think: IE has thousands of hackers over the globe, as well as the IE team at Microsoft, looking for vulnerablities, which get patched (or misused, depending on which team you are!). Who does this for Firefox? Is there a 'Firefox' team that fixes vulnerabilities with the same urgency as the IE team?
Maybe Firefox is just as vulnerable, if not more so, as is IE? I can't see patches being released as efficiently as those for IE.
Durbs rocked!

Nuff said ;)
Another refactoring option available in Whidbey is “Encapsulate Field”.
If I wanted to encapsulate the following private member:

Selecting the menu-item yields the following dialog, which has options regarding the scope of the new property, its name, and (pretty cool) where references to the currently defined variable should be updated:

Changes can be previewed also, just to make sure you don't change anything you don't intend to - the preview looks as follows:

Double-clicking on an entry here takes to to the place in your code where the update will be done, and clicking the “Start” button will make the ammendments. The simple result from my example looks as follows:

Unfortunately, as Frans points out, the area where the code is inserted is entirely up to the likes of Visual Studio itself.
Whidbey rocks. Hard. One of my favourite new features in the code editor is the new “Refactor” menu. Some options here are:
- Extract Method (shown below)
- Encapsulate Field
- Extract Interface
- ...a few more
Some refactoring functionality is not listed on the “Refactor” menu. I have a simple method I'd like to refactor, and this is how can can do it in Whidbey:

I click “Extract Method”, to extract the higlighted code into a seperate method. I supply the method name:

When I click OK, I have to shout “voila!” every time:
Very, very cool.
Whidbey includes nullable types, but for now there's a Sourceforge project to the rescue. NullableTypes for .NET is a very reliable and efficient version of built-in value-types that can be Null. The version 1.2 (stable) has just been released, is features complete and include binary, samples, help files (integrated with VS.NET 2003) and source code.
NullableTypes v1.2 are enabled to work with Web Services, work with .NET Framework 1.0, .NET Framework 1.1 and do compile with MONO and are backward compatible.
Download NullableTypes 1.2 here, or download NullableTypes 1.2 Help (integrated in VS.NET 2003) here.
Visit project home-page for more details.
I went to the Durban July yesterday. For the first time I, too, saw why people here get quite excited by this event: there were more crazy beautiful women per square metre than I have ever witnessed (the horseracing wasn't bad either!). It was an awesome day, and I highly recommend it.
But something a little more exciting: the Mr Price pro surfing comp starts tomorrow. It's an ASP world tour event, and the coolest surfing you'll ever see in SA; it even includes a night surfing competition! Looking forward to that one.
As I'm writing this, wearing a pair of shorts, I realize that tropical Durban is definately where you want to be if you have to spend your winter in South Africa :-P
Today it's official: Microsoft made me a MVP in Visual C#!!! I have no idea how it came about; what I did to deserve this awesome opportunity... I'd like to thank Microsoft, the readers of this blog, my mom and dad, and of course the academy. <tears />
Jokes aside, this is a brilliant opportunity for me - I hope it enables me to serve the community even better :)
Congratulations to Ruari, who also became an MVP today!