Search code examples
c#transparentproxy

Queueing method calls - any idea how?


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 ;)


Solution

  • 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