public RemoteActionAgent(Delegate action, ExceptionKeeper exKeeper, params object[] args)
 {
     m_action   = action;
     m_exKeeper = exKeeper;
     m_args     = args;
     RunAction  = RunActionCore;
 }
        static void RunAtIsolatedProcessCore(string workingDir, string portName, Delegate action, object[] args)
        {
            var retryCount = s_isolatedProcessRecoverableExceptionRetryCount;

            do
            {
                var exKeeper = new ExceptionKeeper();
                var agent    = new RemoteActionAgent(action, exKeeper, args);
                var runner   = new MarshalByRefRunner {
                    Action = agent.RunAction
                };
                var objectUri = typeof(MarshalByRefRunner).FullName + Guid.NewGuid().ToString("N");
                RemotingServices.Marshal(runner, objectUri);
                try
                {
                    var runnerUrl        = "ipc://" + portName + "/" + objectUri;
                    var isolatedProcName = GetIsolatedProcessName();
                    var startInfo        = new ProcessStartInfo(isolatedProcName, runnerUrl)
                    {
                        WorkingDirectory = workingDir,
                        WindowStyle      = ProcessWindowStyle.Hidden
                    };
                    var isolatedProc = Process.Start(startInfo);
                    isolatedProc.WaitForExit();

                    if (exKeeper.SerializationException != null)
                    {
                        throw new ArgumentException(Resources.GetString("AppDomainMixin_RunAtIsolatedXXX_ActionParameterCanNotCrossDomain"), exKeeper.SerializationException);
                    }

                    if (0 < --retryCount && exKeeper.ActionException is RemotingException)
                    {
                        Thread.Sleep(1000);
                    }
                    else if (exKeeper.ActionException != null)
                    {
                        throw new TargetInvocationException(exKeeper.ActionException);
                    }
                    else
                    {
                        retryCount = 0;
                    }
                }
                finally
                {
                    RemotingServices.Disconnect(runner);
                }
            } while (0 < retryCount);
        }