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: code smith, tools
2 Comments:
The updated CoDE article url is http://www.code-magazine.com/article.aspx?quickid=0403071&page=1
By Oskar Austegard, at Friday, June 10, 2005 1:06:00 PM
This blog has been transferred to http://austegard.blogspot.com.
And I gave up on creating a typed backgroundworker component - I'd have to create multiple typed Event Arguments, which wasn't worth the bother. Instead I create simple parameter classes to pass the variables in and out of the backgroundworker component.
See my latest DAL template for an example.
By Oskar Austegard, at Thursday, March 02, 2006 10:06:00 PM
Post a Comment
<< Home