public SharedListenerProxy(SharedConnectionListener parent)
 {
     this.parent                  = parent;
     this.baseAddress             = parent.baseAddress;
     this.queueId                 = parent.queueId;
     this.token                   = parent.token;
     this.onDuplicatedViaCallback = parent.onDuplicatedViaCallback;
     this.isTcp                   = parent.baseAddress.BaseAddress.Scheme.Equals(Uri.UriSchemeNetTcp);
     this.securityEventName       = Guid.NewGuid().ToString();
     this.serviceName             = SharedConnectionListener.GetServiceName(this.isTcp);
 }
            private string HandleServiceStart(bool isReconnecting)
            {
                string listenerEndpoint = null;
                string str4;
                string sharedMemoryName = this.isTcp ? "NetTcpPortSharing/endpoint" : "NetPipeActivator/endpoint";

                this.serviceName = SharedConnectionListener.GetServiceName(this.isTcp);
                if (!isReconnecting && this.ReadEndpoint(sharedMemoryName, out listenerEndpoint))
                {
                    return(listenerEndpoint);
                }
                ServiceController service = new ServiceController(this.serviceName);

                try
                {
                    ServiceControllerStatus status = service.Status;
                    if (isReconnecting && (status == ServiceControllerStatus.Running))
                    {
                        try
                        {
                            string str3 = SharedMemory.Read(sharedMemoryName);
                            if (this.listenerEndPoint != str3)
                            {
                                return(str3);
                            }
                        }
                        catch (Win32Exception exception)
                        {
                            if (DiagnosticUtility.ShouldTraceWarning)
                            {
                                DiagnosticUtility.ExceptionUtility.TraceHandledException(exception, TraceEventType.Warning);
                            }
                        }
                        status = this.ExitServiceStatus(service, 50, 50, ServiceControllerStatus.Running);
                    }
                    if (status == ServiceControllerStatus.Running)
                    {
                        goto Label_021B;
                    }
                    if (!isReconnecting)
                    {
                        try
                        {
                            service.Start();
                            goto Label_01FD;
                        }
                        catch (InvalidOperationException exception2)
                        {
                            Win32Exception innerException = exception2.InnerException as Win32Exception;
                            if (innerException == null)
                            {
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(System.ServiceModel.SR.GetString("SharedManagerBase", new object[] { this.serviceName, System.ServiceModel.SR.GetString("SharedManagerServiceStartFailureNoError") }), exception2));
                            }
                            if (innerException.NativeErrorCode == 0x422)
                            {
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(System.ServiceModel.SR.GetString("SharedManagerBase", new object[] { this.serviceName, System.ServiceModel.SR.GetString("SharedManagerServiceStartFailureDisabled", new object[] { this.serviceName }) }), exception2));
                            }
                            if (innerException.NativeErrorCode != 0x420)
                            {
                                throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(System.ServiceModel.SR.GetString("SharedManagerBase", new object[] { this.serviceName, System.ServiceModel.SR.GetString("SharedManagerServiceStartFailure", new object[] { innerException.NativeErrorCode }) }), exception2));
                            }
                            goto Label_01FD;
                        }
                    }
                    switch (status)
                    {
                    case ServiceControllerStatus.StopPending:
                        status = this.ExitServiceStatus(service, 50, 0x3e8, status);
                        break;

                    case ServiceControllerStatus.Stopped:
                        status = this.ExitServiceStatus(service, 50, 0x3e8, status);
                        break;
                    }
Label_01FD:
                    service.Refresh();
                    status = service.Status;
                    if (status == ServiceControllerStatus.StartPending)
                    {
                        status = this.ExitServiceStatus(service, 50, 50, ServiceControllerStatus.StartPending);
                    }
Label_021B:
                    if (status != ServiceControllerStatus.Running)
                    {
                        throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(new CommunicationException(System.ServiceModel.SR.GetString("SharedManagerBase", new object[] { this.serviceName, System.ServiceModel.SR.GetString("SharedManagerServiceStartFailureNoError") })));
                    }
                }
                finally
                {
                    service.Close();
                }
                try
                {
                    str4 = SharedMemory.Read(sharedMemoryName);
                }
                catch (Win32Exception exception4)
                {
                    throw DiagnosticUtility.ExceptionUtility.ThrowHelperError(this.WrapEndpointReadingException(exception4));
                }
                return(str4);
            }