mo.notono.us

Friday, June 18, 2004

Idea: TypedBackgroundWorker

As mentioned before, I have been wanting to create a wrapper around VS's generated web service proxy classes to simplify asynchronous web service calls for quite some time.

I started with David Hill's Simplified Asynchronous Call Pattern, and added necessary features like trapping server exceptions, etc., as well as adding the option to have the user specify the method to call to end the request.

Then Roy Osherove's post reminded me of the BackgroundWorker code coming in C# 2.0 (and Juwal Lowy's 1.1 implementation), and I finally bothered to do a test implementation. Calling a webservice from the background worker is somewhat different from its intended use, I believe, and it may seem counterintuitive to some that you actually have to call the web method synchronously, but from a background thread, hence achieving the same asynchronous behavior.

I like having a component whose events I can wire up through the designer's property grid, but I am not a fan of the contortions one has to go through to call a method with multiple parameters, or one that contains out or ref parameters. There's only a single Arguments and Results object (which of course makes sense for a generic control) but it means you have to build your own structure for passing in/out multiple values.

So my new top side-project is going to be to create a CodeSmith template that will let you select any method (webservice or "regular") and which creates a typed version of the BackgroundWorker. Ideally I'll also have my generic Component designer control by then to simplify the process.

Stay tuned - it will probably only be a year or so before I get it done...

Labels: ,

2 Comments:

Post a Comment

<< Home