public void Dispose()
 {
     if (this.remoteProxy != null)
     {
         this.remoteProxy.Unregister();
         this.remoteProxy = null;
     }
     if (this.appDomain != null)
     {
         AppDomain.Unload(this.appDomain);
         this.appDomain = null;
     }
 }
        public WorkerAppDomain()
        {
            Assembly       assembly       = typeof(WorkerAppDomain.RemoteProxy).Assembly;
            AppDomainSetup appDomainSetup = new AppDomainSetup();

            appDomainSetup.ApplicationBase = Path.GetDirectoryName(assembly.Location);
            this.appDomain = AppDomain.CreateDomain(assembly.GetName().Name, null, appDomainSetup);
            try
            {
                this.remoteProxy = this.Create <WorkerAppDomain.RemoteProxy>();
            }
            catch
            {
                this.Dispose();
                throw;
            }
        }