Sure...as you've probably noticed I am newish to asynch concepts :),
but here is an BeginSend invocation I am trying to accomplish to use
MR's Async actions:
public IAsyncResult BeginSend(AsyncCallback asyncCallback, object
asyncState, params object[] messages)
{
var ar = new AsyncResult<TResult>(asyncCallback,
messages);
WaitCallback send = state =>
{
try
{
var consumer = new
RequestConsumer<TResult>(ar);
using
(bus.AddInstanceSubscription(consumer))
{
bus.Send(messages);
//wait on new thread for op to
complete inside consumer
ar.AsyncWaitHandle.WaitOne();
}
bus = null;// Allow early GC
}
catch (Exception ex)
{
ar.SetAsCompleted(ex, false);
}
};
ThreadPool.QueueUserWorkItem(send, ar);
return ar;
}
This works fine if the ConsumerOf<> impl has access to the wait handle
being used by the AsyncResult, but that is a constraint I'd rather
avoid. So it'd be good to just call :
bus.MessageProcessingCompleted+=MyHandlerThatSetsTheHandleSignal
I am not proposing to burden IServiceBus with a ton of events, but am
not sure how to accomplish this...
On Dec 22, 11:26 pm, "Ayende Rahien" <[email protected]> wrote:
> Can you explain exactly what you are trying to do? I am not sure that I
> understand.
>
> On Tue, Dec 23, 2008 at 8:21 AM, Mike Nichols <[email protected]>wrote:
>
>
>
> > I want to attach an handle.Set() to fire an 'Consumexxx' is called by
> > RSB. Currently, the events aren't exposed by ITransport to do this
> > (specifically MessageArrived event).
> > My question is, is this a bad idea?
> > I'm working on an BeginSend and EndSend asynch wrapper for RSB but I
> > don't want all my Consumers to require access to the IAsyncResult
> > handle to tell the thread the message is consumed:
>
> > public void Consume(MyMessage msg){
> > //do stuff
> > handle.Set()
> > };
>
> > Really what should be handled is the end of the entire Send()
> > lifecycle (maybe MessageProcessingCompleted but it isn't exposed) so
> > the thread can be told to resume.
>
> > Am I off on this or should some kind of event be exposed for this?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Rhino Tools Dev" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/rhino-tools-dev?hl=en
-~----------~----~----~----~------~----~------~--~---