This blog has been moved to Redwerb.com.

Showing posts with label threading. Show all posts
Showing posts with label threading. Show all posts

Friday, November 30, 2007

Multi-threading just got a little bit easier

Microsoft has just announced that they have "released an early preview of the Parallel Extensions to the .NET Framework (ParallelFX) technology." I haven't had a chance to check this out yet, but it looks like it will provide a new API for managing threading. What looks especially interesting are the multi-threaded foreach loops.

I don't want to say too much because I really don't know much about it, but check out the announcement on Somasegar's blog, Parallel Extensions to the .NET FX CTP.

Saturday, November 11, 2006

Event-Based Asynchronous WebRequest

I've created my first Code Project article! I was looking for a place to upload some code so I could share it from my blog, but the only place that I could find was Code Project, of course that meant that I had to write an article too.

If you are interested in reading about using the WebRequest/WebResponse classes (including processing of the response stream) or implementing the Event-Based Asynchronous Pattern (the pattern used by the BackgroundWorker component), you can read my article at Event-Based Asynchronous WebRequest.

The article includes a project that contains a BackgroundWebRequest component that can be used to perform asynchronous web requests from a WinForm application.

Friday, November 10, 2006

The Holy Grail of .Net Threading

The Epiphany

I was working on a project that needed to be able to process a WebRequest/WebResponse from a thread within a WinForm application. I tried several approaches, including using a BackgroundWorker, however, what I really wanted to do was create my own component similar to the BackgroundWorker, but specifically for WebRequests. Unfortunately, I didn't know how they did it.

As I was driving home from work I had an epiphany. The obvious solution would be to use Reflector for .NET to figure out how Microsoft did it.

Meeting Up With Sir Galahad

I opened the class up in Reflector and used the File Disassembler (an add-in to Reflector) to output it as a VB class. I waded through the code trying to understand what it did when I found the first hint as to the location of the Holy Grail, the AsyncOperation class.

This class looked important in the threading for BackgroundWorker, so I looked up the documentation for it. In the first sentence of the remarks, it contained a link to the Holy Grail.

The Holy Grail of .Net Threading

The Event-based Asynchronous Pattern is a design pattern that is useful for creating a class that can run operations on a separate thread, but will raise events on the main thread (very useful for threading in WinForms).

MSDN has a series of articles that clearly describe this pattern and how to implement it. The Asynchronous Programming Design Patterns node in the MSDN documentation discusses several different asynchronous patterns that you can use.