The Old New Thing

Practical development throughout the evolution of Windows.

Latest posts

C# static constructors are called on demand, not at startup
Aug 15, 2007
Post comments count 0
Post likes count 0

C# static constructors are called on demand, not at startup

Raymond Chen
Raymond Chen

One of the differences between C++ and C# is when static constructors run. In C++, static constructors are the first thing run in a module, even before the function runs.¹ In C#, however, static constructors don't run until you use the class for the first time. If your static constructor has side effects, you may find yourself experiencing those side effects in strange ways. Consider the following program. It's rather contrived and artificial, but it's based on an actual program that encountered the same problem. This program tries to set an invalid event, so the call to is expected to fail with an ...

SIFF 2007 wrap-up: Grandhotel, The Boss of It All, Vacation
Aug 14, 2007
Post comments count 0
Post likes count 0

SIFF 2007 wrap-up: Grandhotel, The Boss of It All, Vacation

Raymond Chen
Raymond Chen

Sorry, SIFF fans, but this article got stuck in the queue. But now it's unstuck. Grandhotel : A sweet story about a shy, innocent, weather-obsessed hotel employee and the even stranger people who surround him. I wasn't quite sure what to expect, but I was quite pleased with what I got. Part comedy, part drama, the movie creates touching moments while remaining true to the quirky nature of its characters. I give it a 3 out of 5. The Boss of It All: A company's founder blames all unpopular decisions on his imaginary boss, but when he enters negotiations to sell the company, he must produce this elusive boss an...

What is the order of evaluation in C#?
Aug 14, 2007
Post comments count 0
Post likes count 0

What is the order of evaluation in C#?

Raymond Chen
Raymond Chen

The C and C++ languages leave the order of evaluation generally unspecified aside from specific locations called sequence points. Side effects of operations performed prior to the sequence point are guaranteed visible to operations performed after it.¹ For example, the C comma operator introduces a sequence point. When you write f(), g(), the language guarantees that any changes to program state made by the function can be seen by the function ; executes before . On the other hand, the multiplication operator does not introduce a sequence point. If you write there is no guarantee which side will be evalu...

Math is hard, let's go shopp—oops
Aug 13, 2007
Post comments count 0
Post likes count 0

Math is hard, let's go shopp—oops

Raymond Chen
Raymond Chen

(The title is another variation on Math is hard, let's go shopping!", which appears to be a popular catchphrase over in Michael Kaplan's neck of the woods. The history of the phrase was researched on Language Log.) Last spring, I was at a local crafts store and paid for a $2.15 item with a $5 bill and two dimes. The teenage salesclerk rang up the sale and began to give me $17.90 in change. "Um, I gave you $5.20." You'd think the salesclerk would notice something strange when the amount of change exceeded the amount of cash tendered! "Oh, right." The salesclerk had entered $20.05 instead of $5.20. But now ca...

Why is the blog's subtitle "Not actually a .NET blog"?
Aug 13, 2007
Post comments count 0
Post likes count 0

Why is the blog's subtitle "Not actually a .NET blog"?

Raymond Chen
Raymond Chen

Based on the feedback from my last CLR week, I think one CLR week a year is about right, Welcome to CLR Week 2007. I'll kick off the week with something not actually technical, but which might be puzzling to the newcomers: Why is the blog's subtitle "Not actually a .NET blog"? When I started, the blog hosting site for Microsoft technical bloggers was blogs.gotdotnet.com, and this site was consequently located at blogs.gotdotnet.com/oldnewthing. (The old address still works. Blog backward compatibility, I guess.) It was the .NET folks like Brad Abrams and Chris Brumme who started the big wave of Microsoft blog...

Things I've written that have amused other people, Episode 4
Aug 10, 2007
Post comments count 0
Post likes count 0

Things I've written that have amused other people, Episode 4

Raymond Chen
Raymond Chen

One of my colleagues pointed out that my web site is listed in the references section of this whitepaper. It scares me that I'm being used as formal documentation because that is explicitly what this web site isn't. I wrote back, I really need to put a disclaimer on my web site. FOR ENTERTAINMENT PURPOSES ONLY Remember, this is a blog. The opinions (and even some facts) expressed here are those of the author and do not necessarily reflect those of Microsoft Corporation. Nothing I write here creates an obligation on Microsoft or establishes the company's official position on anything. I am not a spokesperson...

Martina Navratilova's final Wimbledon appearance, and this time she means it
Aug 9, 2007
Post comments count 0
Post likes count 0

Martina Navratilova's final Wimbledon appearance, and this time she means it

Raymond Chen
Raymond Chen

When I was growing up, our family followed professional tennis on television, and Wimbledon was of course the tennis tournament of the year. During those years, it seemed always to boil down to Martina Navratilova against Chris Evert in the final, and the family's loyalties were split. (I sided with the old guard and pulled for Chris Evert.) In this NPR interview, Martina Navratilova talks about her retirement (she really means it this time), looks back at the years she dominated women's tennis, how she and Chris Evert got along off the court, and how she is disappointed with the current generation of players w...

How do I get the handle of the primary monitor?
Aug 9, 2007
Post comments count 0
Post likes count 1

How do I get the handle of the primary monitor?

Raymond Chen
Raymond Chen

The primary monitor by definition has its upper left corner at (0, 0). Therefore, you can use this function: To make double extra sure (belt and suspenders), we also tell it, "If you're not sure what monitor to return, give us the primary." Sure, this sounds obviously simple, but I actually found somebody who fumbled around in the dark passing intentionally invalid parameters to trying to find one that would return the primary monitor handle. (I've heard this called Programming By Accident.)

Bowling coming to Bellevue, and given the location, it's naturally upscale
Aug 8, 2007
Post comments count 0
Post likes count 0

Bowling coming to Bellevue, and given the location, it's naturally upscale

Raymond Chen
Raymond Chen

The Lincoln Square mall in Bellevue will have a new tenant: An upscale bowling all^H^H^Hlounge. Expected to open before the Christmas holiday season, there will be two bars, full-service dining, lots of big plasma screens, all the stuff that makes bowling better. The lounge be positioned on the second floor, beneath Parlor Billiards, a business which by a fantastic coincidence has exactly the same business model as the bowling all^H^H^Hlounge, but with billiards instead of bowling. By Christmastime, the 23,900 square foot venue will be the site of strikes, splits, and, no doubt, lots of failed pick-up attemp...