private void DisposeClient() { if (_client != null) { _client.Dispose(); _client = null; } }
/// <summary> /// Starts the remote process which will host an Activator /// </summary> public void Start() { CheckDisposed(); DisposeClient(); Logger.InfoFormat("Starting process for Process Domain '{0}'", _friendlyName); String processGuid = Guid.NewGuid().ToString(); bool created; var serverStartedHandle = new EventWaitHandle(false, EventResetMode.ManualReset, string.Format(ActivatorHost.EventName, processGuid), out created); // We set guid to a new value every time therefore this "should" never happen. if (!created) { throw new Exception("Event handle already existed for remote process"); } string processDomainAssemblyPath = AssemblyUtils.GetFilePathFromFileUri(typeof(ActivatorProcess).Assembly.CodeBase); ProcessDomainSetup.Serialize(_setupInfo, _setupInfoFile); // args[0] = process domain assembly path // args[1] = guid // args[2] = process id // args[3] = ProcessDomainSetup file _process.StartInfo.Arguments = string.Format("\"{0}\" {1} {2} \"{3}\"", processDomainAssemblyPath, processGuid, Process.GetCurrentProcess().Id, _setupInfoFile); if (!_process.Start()) { throw new Exception(string.Format("Failed to start process from: {0}", _process.StartInfo.FileName)); } Logger.InfoFormat("Process successfully started with process id {0}", _process.Id); if (!serverStartedHandle.WaitOne(_setupInfo.ProcessStartTimeout)) { throw new Exception("Timed-out waiting for remote process to start"); } serverStartedHandle.Close(); _processStatus = ProcessStatus.Active; _process.PriorityClass = _setupInfo.PriorityClass; _client = new ActivatorClient(processGuid, _setupInfo); var tmp = Attached; if (tmp != null) { tmp(); } }