Queue on a Windows Service
Posted on 2005-05-17
Several users will connect to this WS thru Remoting, requesting certain tasks.
Some interesting points:
0- You can think of this as the SQL Server service, but this one receives more requests than only DB interactions.
1- Some of the task don't return any value but some (most of them) do.
> So I want the clients to place the request and receive the response using a single Function.
2- The WS must allways be available to process new requests.
> The WS must never be as "not responding" because it's processing a request... (allways async calls)
Now, what is my problem...
When the client places the request, I need to find a way to make the code stop and wait for the response inside the caller function, otherwise I can't imagine other way to return the request result thru the same function that have placed the request.
What have I tried:
1- Make a sync delegate.
> Works on the idea of blocking the client side process, but then I'll have to wait for the service-side process to wait for the request to be processed from the queue...
2- Make an async delegate.
> Works a little better than the previous but still I need to wait somewhere on the delegate method on on the callback for the request to be processed from the queue.
> On this scenario I use the WaitHandle to stop the process, activating the WaitOne method.
3- Regarding the waiting process...
> As for the waiting process, I'm using a Do : Loop Until (the result value is something other than nothing) but this if a terrible CPU resources trasher...
I'm awhare that this isn't an easy thing, neither to understand or develop, but I really need this to work... need some ideas!
Thank you very much...