Saturday, September 08, 2007

Asynchronous delegates in .NET

Delegates - Delegates are type safe function pointers that are usually used as a enabler of call back mechanism. Delegates are synchronous by default in the .NET environment. Which means when an event is fired and a delegate is invoked, the delegate is completed synchronously. This could be made asynchronous too, but why?
Say for example in my case I have a .NET remoted server which could be connected by various clients and each client that is connecting could send requests and get a response back from the server. So what happens if an event in the server has its subscriptions in the client side, say there are three subscriptions. We know that in a multiple subscription scenario the invocation goes from the first subscriber until the next in a sequential order. And what if an exception gets thrown while in the middle of executing the subscriber's procedure? The others in the subscription list have to wait until the exception is being handled. In this case we would want to make the mechanism asynchronous providing control to the server so that the other clients who are in the queue of being serviced will not be waiting for ever.

Asynchronous delegate

No comments: