private static void DoWorkInShadowCopiedDomain()
        {
            var queueName = (string)AppDomain.CurrentDomain.GetData("QueueName");
            var autoShutdownMemoryThresholdBytes = (long?)AppDomain.CurrentDomain.GetData("AutoShutdownMemoryThresholdBytes");
            GenericWorkerProcess process         = new GenericWorkerProcess(CreateUnityContainer(queueName, autoShutdownMemoryThresholdBytes));

            //execute
            GenericWorkerProcessRun(process, queueName);
        }
 private static void GenericWorkerProcessRun(GenericWorkerProcess process, string queueName)
 {
     try
     {
         process.Run(queueName);
     }
     catch (ReflectionTypeLoadException ex)
     {
         HandleReflectionTypeLoadException(ex);
     }
     catch (Exception ex)
     {
         HandleException(ex);
     }
 }
        private static void StartWorkerProcess(Options commandLineOptions, bool shadowCopy)
        {
            if (shadowCopy)
            {
                //start in new appDomain
                var appDomainSetup = new AppDomainSetup {
                    ShadowCopyFiles = "true"
                };
                var applicationName = string.Format("GenericWorker.exe {0}", commandLineOptions.QueueName);
                var appDomain       = AppDomain.CreateDomain(applicationName, AppDomain.CurrentDomain.Evidence, appDomainSetup);
                appDomain.SetData("QueueName", commandLineOptions.QueueName);
                appDomain.SetData("AutoShutdownMemoryThresholdBytes", commandLineOptions.AutoShutdownMemoryThresholdBytes);
                appDomain.DoCallBack(new CrossAppDomainDelegate(DoWorkInShadowCopiedDomain));
            }
            else
            {
                //start in host appDomain
                GenericWorkerProcess process = new GenericWorkerProcess(CreateUnityContainer(commandLineOptions.QueueName, commandLineOptions.AutoShutdownMemoryThresholdBytes));

                //execute
                GenericWorkerProcessRun(process, commandLineOptions.QueueName);
            }
        }