Daily Archives: September 3, 2006

Async in asp.net 2.0- don’t forget that iAsyncResult!

One of the points of confusion I’ve seen wrt these new asp.net features is people trying to use them (and getting no farther than head banging) with random functions.

.NET 2.0 makes a lot of asynchronous stuff much easier with the Event Driven Asynchronous Pattern.

The BackgroundWorker sets up the entire package for  you and is a great solution for Windows Forms.

But with the ASP.NET 2.0 methods, you must call out to methods that already have BeginInvoke/EndInvoke and that return IAsyncResult. It’s easy to do with classes that already do this – like the new SQLCommand Async functions (eg. BeginExecuteReader/EndExecuteReader) or calls using HTTPRequest to pull down data from another website (eg an RSS Feed). But what about doing long running processes that don’t have .NET (or 3rd party) calls that implement the async pattern? What if you have a website that does the ever popular Fibonacci calculation? (Not really “ever-popular”, though it is the common example of long running method used in MSDN docs ;-)).

The grown-up way is to create a delegate for your synchronous method and then call BeginInvoke and EndInvoke. Here’s some help with that.

An easy way that doesn’t require mucking with delegates is to stuff the function into a web service then use the web services async functionality (which come for free when you build a web service proxy through Visual Studio). Prior to VS2005, we had only the Begin/End methods availalbe. VS2005 has those plus a new pair that ift into the Event Driven Async Pattern: myMethodAsync & myMethodCompleted. You can see both of these in the above link.

Productive Procrastination

How about attempting to sort out and file away 8 months of bills, etc that have been piling up in my filing in-box?

It’s hard to tell by the picture, but there is a LOT of paper in these piles. On CSI, of course, you’d be able to zoom in on this image …

…and then “enhance” it, to make it perfectly legible and clear. Of course, you wouldn’t think of that unless Horatio Caine was standing over your shoulder, looking in the other direction, saying, “hmmmmmmmmmm, what I want you to do…. what I want you to do, is zoom in on that picture. Yes. Now enhance it.”. Then slide his head around to give you the snake eyed glare. God that makes us laugh… ever predictable.

If that total fantasy isn’t the fantasy that I think it is, I guess I’m pretty much screwed.

Petzold’s new WPF book: “Availability: In Stock”

Huge congrats to Charles on another important Windows programming classic-to-be: Applications = Code + Markup: A Guide to the Microsoft Windows Presentation Foundation

Karsten J (who knows WPF well enough to be a great judge of the book’s worthiness) has high praise for the book: “The book is pedagogically brilliant”.

I especially love that he says:  “It actually does read like a novel to me, with a narrative arch as it negotiates its methodical way through the WPF jungle of APIs.” This is what makes Charles’ books such awesome reading. He’s very literate and a great story teller. So even when writing about technical stuff, it’s so palatable. Who else would so naturally insert analogies to Greek mythology or the affairs of 18th century French courtisans into explanations of software development?

I am so currently mired in VS2005 stuff that my inability to dive into WPF, Vista, WCF, ADO.NET v.next, etc. is a constant challenge to my attempts to keeping some balance in  my life. Perhaps when I finish my current bedside reading, I’ll just have to break my golden rule again, and stick this on the nightstand!

Going to Bumbershoot? Look for Alison Bechdel Monday at 6:30.

Okay all my Seattleite pals: Alison Bechdel, author of Dykes to Watch Out For, who has been rocketed to wider fame beyond her popular strip by her new book Fun Home, will be at Bumbershoot tomorrow night (Monday). She won’t arrive in Seattle loaded down with maple syrup and Vermont Coffee Company coffee like I usually am when I come to Microsoft (she’ll be happy if her necessary liquids arrive), she’s slinging a lot more interesting stuff than code!

Monday, 6:30 pm – 7:30 pm @ Alki Room

Alison lives nearby, so I love watching what she’s up to and making sure nobody’s missing out on her! I know Fun Home has been making the rounds here in Huntington!

Don’t Forget: www.acehaid.org