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: 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: Ice arrows?

Interviewer: Why?

Me: 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:

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

Me: 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

November 21, 2005 .net

WinFX November 2005 CTP

You’ve probably seen this by now, but I thought I’d post the WinFX Nov05 CTP-related links together in a spot where I could find them later. In addition to being closer to what we plan on shipping, this CTP also works with VS05 RTM:

Enjoy!

November 16, 2005 tools

Lots of WinForms 2.0 Chewy Goodness

Here. The WinForms team has put up all kinds of WinForms 2.0 resources, including a bunch of FAQs and samples. Enjoy.
November 15, 2005 spout

Turning off special features in DVDs and CDs?

Does anyone know if it’s possible to turn off the special PC features of DVDs and CDs? I’d like to avoid Sony-sponsored virus enablers on CDs and required players for DVD content and just treat each of these CDs and DVDs as un-special. Is such a thing possible?
November 13, 2005 fun

Dilbert on Trial Redundancy

As an engineer, I appreciate the efficiency of combining the criminal and civil trials into one. Plus, if it weren’t for women who have inexplicably bad judgment,” I’d never have reproduced. : )
November 13, 2005 spout

USB HD w/ OS/Apps + FolderShare = Portable Computing?

If you could boot Windows Vista from a USB drive large enough for the OS and apps, like this version of Linux, and log into FolderShare for your data, you could use any computer that allowing booting from USB into a temporary terminal (although device drivers would be a challenge).


← Newer Entries Older Entries →