views:

82

answers:

2

I write a heavily asynchronseous application.

I am looking for a way to queue method calls, similar to what BeginInvoke / EndInvoke does.... but on my OWN queue. The reaqson is that I am having my own optimized message queueing system using a threadpool but at the same time making sure every component is single threaded in the requests (i.e. one thread only handles messages for a component).

I Have a lot of messages going back and forth. For limited use, I would really love to be able to just queue a message call with parameters, instead of having to define my own parameter, method wrapping / unwrapping just for the sake of doing a lot of admnistrative calls. I also do not always want to bypass the queue, and I definitely do not want the sending service to wait for the other service to respond.

Anyone knows of a way to intercept a method call? Some way to utilize TransparentProxy / Virtual Proxy for this? ;) ServicedComponent? I would like this to be as little overhead as possible ;)

+3  A: 

How about using lambdas?

I mean, why don't you create some Queue, and process them in manner like

while (!queue.Empty) 
{
    Action action = queue.Pop();
    action(); // this calls your action
}

You can add actions very simply:

Queue.Add( ()=>{  /* any code you wish here */})

This is just a tip, I'm not sure if there is some Queue class, but it should be pretty straightforward to create one (and threadsafe!) by yourself.

The workaround could (and should) be much wiser, but the main point is there. Write me if you want to consult.

Pz, the TaskConnect developer

Pz
TGhe queueing is not the problem ;) I have that one already, and a lot of messages that transport data updates. My problem are function calls only. The queue then uses a ThreadPool to get a worker thread that processes it's content ;) I have a lot of cross process data update stuff there - now I look for a way to queue (in process) method calls. One message type that has no "data" but a function call with all the parameters, so I can basicall call methods on the target service. This would significantly cut down on the number of different messages I need...
TomTom
and I would not have to come up with a hugh switch statement just for calling different methods.
TomTom
Since you are looking to queue in-process method calls, passing lambdas seems to be exactly what you are looking for...
Justin Ethier
A: 

The DynamicProxy that is part of the Castle project allows object member interception without some of the typical Marshalling pain

http://www.castleproject.org/dynamicproxy/index.html

You could use this to intercept your methods calls and then do with them what you want.

Foovanadil