December 18, 2005 spout

How come nobody says “impeach?”

WARNING: This is my political side bubbling over. If you only want fun stuff about my kids or technology, this post ain’t for you.

Clinton engaged in an consensual adult act in the west wing and endured the impeachment process.

Bush sics the NSA on us w/o due process, starts a war so he can look tough for his dad and continues to dismiss global warming as a myth. Why aren’t we impeaching his ass?

December 16, 2005 spout writing

Windows Forms 2.0 Book Samples Posted

Mike did some last minute clean-up and checked in the files, so I’ve uploaded the code sample for the Windows Forms 2.0 book. Enjoy.

December 16, 2005 spout writing

Windows Forms Programming 2005 in C# Submitted!

I packaged off the final chapters, figures and PDF files for submission of the WinForms 2.0 book this morning. Michael made it easy by fixing all the last minute nits I found, producing the PDFs and bundling all of the figure files together (he separated the graphics from the Word docs using a WinForms 2.0 program, of course!).

In spite of the fact that I’ve been working on long-lead prototype coding for the last month and Mike’s been moving to the US from Australia, we managed to get the book submitted a full 15.5 hours early (they meant midnight when they gave us a 12/16 deadline, didn’t they?!?).

I’m so excited to get the book in your hands, that I’ve asked Mike to check in the files he’s got checked out so that we can post the code samples ASAP. It’ll still be a while before the book is in your hands, though. We took 22 months to write it, but it’s the 3 months it takes to print it that always sticks in my craw the most for some reason. : )

Wahoo (2)!

December 9, 2005 tools

Windows Template Library (WTL) 7.5

It looks like my old friend Nenad Stefanovic is up to his old tricks with a new version of my favorite native framework, the Windows Template Library. This will go nicely with ATL Internals, 2e, which Chris Tavares is finishing up for Brent and me.

[via Shawn Wildermuth]

November 26, 2005 fun

Wasting the Prince of Darkness

80% of the email I get about my Microsoft interview question site (which, 2.5 years into my MS career, nobody has yet forced me to take down) isn’t very fun, e.g. asking for the answers (which I don’t give) or fairly pedestrian stories (“I got asked some regular questions but didn’t get hired.“).

This one, though, is definitely worth posting. Enjoy!

November 23, 2005 interview

Wasting the Prince of Darkness

From “Pete” (not his real name):

I walked into my first technical interview at Microsoft, and before I could say anything, the woman says, Youre in an 8x8 stone corridor. I blink and sit down.

Interviewer: The prince of darkness appears before you.

Me: You mean, like, the devil?

Interviewer: Any prince of darkness will do.

Me: Ok.

Interviewer: What do you do?

Me: <pause> Can I run?

Interviewer: Do you want to run?

Me: Hmm I guess not Do I have a weapon?

Interviewer: What kind of weapon do you want?

Me: Um something with range?

Interviewer: Like what?

Me: Uh a crossbow?

Interviewer: What kind of ammo do you have?

Me: <long pause> Ice arrows?

Interviewer: Why?

Me: <floundering> Because the prince of darkness is a creature made of fire???

Interviewer: Fine so what do you do next?

Me: I shoot him?

Interviewer: No what do you do?

Me: <blank stare>

Interviewer: You WASTE him! You *WASTE* the prince of darkness!!

Me: <completely freaked out and off my game> Holy crap what have I gotten myself into.

She then tells me that she asks that question for two reasons. 1) Because she wants to know if the candidate is a gamer (which is apparently really important please note: Im not a gamer) and 2) because she wants her question to show up on some website. I hate to accommodate her, but this is definitely the weirdest interview question Ive ever heard of.

Well, here you go, weird-prince-of-darkness-wasting-lady…

November 23, 2005 spout

A C# 2.0 anon delegate “gotcha”

I’m a huge fan of anonymous delegates, but I ran into a gotcha this morning when using anon delegates inside a for-loop:

class Worker {

  public event WorkCompleted Completed;

 

  public void DoWork() {

    Console.WriteLine(“Worker: work completed”);

    if( this.Completed != null ) {

      foreach( WorkCompleted wc in this.Completed.GetInvocationList() )

        wc.BeginInvoke(delegate(IAsyncResult result) {

          // Use wc from surrounding context

          int grade = wc.EndInvoke(result);

          Console.WriteLine(“Worker grade= {0}”, grade);

        },

        null);

      }

    }

  }

}

When I run this code, I get the follow exception:

System.InvalidOperationException:
  The IAsyncResult object provided does not match
  this delegate.

What’s happening, of course, is that the wc variable continues to change after the dynamic invocation happens instead of the value being stored away, one for each call to BeginInvoke, as I’d intended. One fix for this problem is to pass the value I wish I could take off the stack as the async state argument:

class Worker {

  public event WorkCompleted Completed;

 

  public void DoWork() {

    Console.WriteLine(“Worker: work completed”);

    if( this.Completed != null ) {

      foreach( WorkCompleted wc in this.Completed.GetInvocationList() ) {

        wc.BeginInvoke(delegate(IAsyncResult result) {

          // Pull the value out of async state

          WorkCompleted wc2 = (WorkCompleted)result.AsyncState;

          int grade = wc2.EndInvoke(result);

          Console.WriteLine(“Worker grade= {0}”, grade);

        },

        wc);

      }

    }

  }

}

This isn’t quite the elegant code I’d like to write with anon delegates, however. I can do a little better by creating a variable on the stack specifically for use in the delegate:

class Worker {

  public event WorkCompleted Completed;

 

  public void DoWork() {

    Console.WriteLine(“Worker: work completed”);

    if( this.Completed != null ) {

      foreach( WorkCompleted wc in this.Completed.GetInvocationList() ) {

        WorkCompleted wc2 = wc; // Copy wc for use in delegate

        wc.BeginInvoke(delegate(IAsyncResult result) {

          int grade = wc2.EndInvoke(result);

          Console.WriteLine(“Worker grade= {0}”, grade);

        },

        null);

      }

    }

  }

}

In this case, each time through the loop, a new variable is created on the stack specifically for that invocation of the loop and is therefore unchanged by the time the anon delegate is executed. This still isn’t quite ideal, but it’s not too bad.

November 22, 2005

Use IM to Ask Encarta

If you add encarta@conversagent.com to your MSN IM contacts list, you can ask it questions, e.g.

  • What is the size of Mexico?
  • When was Leonardo da Vinci born?
  • How many calories are there in an orange?
  • I want to see the map of Italy.
  • When was Abraham Lincoln born?
  • Solve 2x^2+7x=5

I especial love the “solve” thing. If I could figure out how to give it simultaneous equations, most of my boys’ math home would be solved in IM…


← Newer Entries Older Entries →