public int InvokeAsyncRequest(ProxyOutgoingAsyncBase outAsync, bool synchronous) { // // Increase the direct count to prevent the thread pool from being destroyed before // invokeAll is called. This will also throw if the object adapter has been deactivated. // _adapter.IncDirectCount(); int requestId = 0; try { lock (this) { outAsync.Cancelable(this); // This will throw if the request is canceled if (!outAsync.IsOneway) { requestId = ++_requestId; _asyncRequests.Add(requestId, outAsync); } _sendAsyncRequests.Add(outAsync, requestId); } } catch (System.Exception) { _adapter.DecDirectCount(); throw; } outAsync.AttachCollocatedObserver(_adapter, requestId, outAsync.RequestFrame.Size); if (!synchronous || outAsync.IsOneway || _reference.InvocationTimeout > 0) { // Don't invoke from the user thread if async or invocation timeout is set // TODO: why is oneway included in this list? _adapter.ThreadPool.Dispatch( () => { if (SentAsync(outAsync)) { ValueTask vt = InvokeAllAsync(outAsync.RequestFrame, requestId); // TODO: do something with the value task } }); } else // Optimization: directly call invokeAll { if (SentAsync(outAsync)) { Debug.Assert(outAsync.RequestFrame != null); ValueTask vt = InvokeAllAsync(outAsync.RequestFrame, requestId); // TODO: do something with the value task } } return(OutgoingAsyncBase.AsyncStatusQueued); }
public void InvokeAsyncRequest(ProxyOutgoingAsyncBase outAsync, bool synchronous) { // // Increase the direct count to prevent the thread pool from being destroyed before // invokeAll is called. This will also throw if the object adapter has been deactivated. // _adapter.IncDirectCount(); int requestId = 0; try { lock (this) { outAsync.Cancelable(this); // This will throw if the request is canceled if (!outAsync.IsOneway) { requestId = ++_requestId; _asyncRequests.Add(requestId, outAsync); } _sendAsyncRequests.Add(outAsync, requestId); } } catch (Exception) { _adapter.DecDirectCount(); throw; } outAsync.AttachCollocatedObserver(_adapter, requestId, outAsync.RequestFrame.Size); if (_adapter.TaskScheduler != null || !synchronous || outAsync.IsOneway || _reference.InvocationTimeout > 0) { // Don't invoke from the user thread if async or invocation timeout is set. We also don't dispatch // oneway from the user thread to match the non-collocated behavior where the oneway synchronous // request returns as soon as it's sent over the transport. Task.Factory.StartNew( () => { if (SentAsync(outAsync)) { ValueTask vt = InvokeAllAsync(outAsync.RequestFrame, requestId); // TODO: do something with the value task } }, default, TaskCreationOptions.None, _adapter.TaskScheduler ?? TaskScheduler.Default);