public int InvokeAsyncRequest(OutgoingAsyncBase 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 (_response) { requestId = ++_requestId; _asyncRequests.Add(requestId, outAsync); } _sendAsyncRequests.Add(outAsync, requestId); } } catch (Exception) { _adapter.DecDirectCount(); throw; } outAsync.AttachCollocatedObserver(_adapter, requestId); if (!synchronous || !_response || _reference.GetInvocationTimeout() > 0) { // Don't invoke from the user thread if async or invocation timeout is set _adapter.ThreadPool.Dispatch( () => { if (SentAsync(outAsync)) { ValueTask vt = InvokeAllAsync(outAsync.GetOs(), requestId); // TODO: do something with the value task } }); } else // Optimization: directly call invokeAll { if (SentAsync(outAsync)) { ValueTask vt = InvokeAllAsync(outAsync.GetOs(), requestId); // TODO: do something with the value task } } return(OutgoingAsyncBase.AsyncStatusQueued); }