/// <summary> /// Method DisposeClient. /// </summary> private void DisposeClient() { if (this._addInActivatorClient != null) { this._addInActivatorClient.Dispose(); this._addInActivatorClient = null; } }
public void Start() { this.CheckDisposed(); this.DisposeClient(); string guid = Guid.NewGuid().ToString(); bool isCreated; using (EventWaitHandle serverStartedHandle = new EventWaitHandle(false, EventResetMode.ManualReset, string.Format(AddInActivatorHost.AddInDomainEventNameStringFormat, guid), out isCreated)) { if (!isCreated) { throw new Exception(AddInConstants.EventHandleAlreadyExistedException); } string addInDomainAssemblyPath = typeof(AddInActivatorProcess).Assembly.Location; AddInDomainSetup.WriteSetupFile(this._addInDomainSetup, this._addInDomainSetupFile); //// args[0] = AddInDomain assembly path //// args[1] = GUID //// args[2] = PID //// args[3] = AddInDomainSetup file //// args[4] = Redirect output or not this._process.StartInfo.Arguments = string.Format("\"{0}\" {1} {2} \"{3}\" {4}", addInDomainAssemblyPath, guid, Process.GetCurrentProcess().Id.ToString(), this._addInDomainSetupFile, this._redirectOutput.ToString()); this.IsRunning = this._process.Start(); if (!this.IsRunning) { Debug.WriteLine(string.Format(AddInConstants.ProcessStartExceptionStringFormat, this._process.StartInfo.FileName)); throw new Exception(string.Format(AddInConstants.ProcessStartExceptionStringFormat, this._process.StartInfo.FileName)); } if (!serverStartedHandle.WaitOne(this._addInDomainSetup.ProcessStartTimeout)) { Debug.WriteLine(AddInConstants.ProcessStartTimeoutException); throw new Exception(AddInConstants.ProcessStartTimeoutException); } this._process.BeginOutputReadLine(); this._process.BeginErrorReadLine(); this._process.PriorityClass = this._addInDomainSetup.ProcessPriority; this._addInActivatorClient = new AddInActivatorClient(guid, this._addInDomainSetup); this.RaiseEvent(this.Attached); } }