internal void Enqueue(RunnerContext ctx, object[] args)
 {
     int index = ctx.CallIndex;
     m_factory.StartNew(() =>
     {
         ctx.PutResult(ctx.MethodInfo.Invoke(ctx.Object, args), index);
         if (ctx.CallsLeft <= 0)
             ctx.Connection.Respond(ctx);
     });
 }
        /*
        private void ProcessMessage()
        {
            var od = new ObjectDeserializer(m_bufferStream);

            var ctx = new RunnerContext(this);
            var msg = (RunMessage)od.Read();
            string staticName = string.Empty;

            if (msg.IsStatic)
                staticName = (string)od.Read();
            else
                ctx.Object = od.Read();

            for(int i = 0; i < msg.NumCalls; i++)
            {
                var args = (object[])od.Read();
                ctx.Arguments.Add(args);
            }

            //if (msg.IsStatic)

            else

            // parent run context
            Extensions.Go(() => { m_parent.Execute(ctx); });
        }*/
        internal void Respond(RunnerContext ctx)
        {
            Debug.Print("+ RemoteRunnerConnection.Respond");

            var resp = new RunResultMessage { Success = true, NumResults = ctx.Results.Count };
            var os = new ObjectSerializer(m_stream);
            os.Write(resp);
            foreach (var res in ctx.Results)
                os.Write(res);

            Debug.Print("- RemoteRunnerConnection.Respond");
        }
        private void ProcessMessage(IAsyncResult ar)
        {
            Debug.Print("+ RemoteRunnerConnection.ProcessMessage");

            var msg = (RunMessage)m_output.EndRead(ar);
            var ctx = new RunnerContext(this, msg.NumCalls);

            m_output.BeginRead(ProcessObject, new State() { Msg = msg, Ctx = ctx });
        }