private PackageManagerResponseImpl PerformCall(InvokeMemberBinder binder, object[] args) { using (var eventQueue = new ManualEventQueue()) { // create return message handler var responseHandler = new PackageManagerResponseImpl(); CurrentTask.Events += new GetCurrentRequestId(() => "" + Task.CurrentId); // unhook the old one if it's there. responseHandler.Clear(); // send OG message here! object callResult; base.TryInvokeMember(binder, args, out callResult); // will return when the final message comes thru. eventQueue.StillWorking = true; while (eventQueue.StillWorking && eventQueue.ResetEvent.WaitOne()) { eventQueue.ResetEvent.Reset(); while (eventQueue.Count > 0) { if (!Event <GetResponseDispatcher> .RaiseFirst().DispatchSynchronous(eventQueue.Dequeue())) { eventQueue.StillWorking = false; } } } if (PackageManagerResponseImpl.EngineRestarting) { Logger.Message("Going to try and re issue the call."); // Disconnect(); // the service is going to restart, let's call TryInvokeMember again. EngineServiceManager.WaitForStableMoment(); Connect().Wait(); return(PerformCall(binder, args)); } // this returns the final response back via the Task<*> return(responseHandler); } }