public void Stop()
        {
            Client.Network.EventQueueRunning -= new EventHandler <EventQueueRunningEventArgs>(Network_EventQueueRunning);

            // Connection events
            OnDaemonRunning -=
                new VoiceGateway.DaemonRunningCallback(connector_OnDaemonRunning);
            OnDaemonCouldntRun -=
                new VoiceGateway.DaemonCouldntRunCallback(connector_OnDaemonCouldntRun);
            OnConnectorCreateResponse -=
                new EventHandler <VoiceGateway.VoiceConnectorEventArgs>(connector_OnConnectorCreateResponse);
            OnDaemonConnected -=
                new VoiceGateway.DaemonConnectedCallback(connector_OnDaemonConnected);
            OnDaemonCouldntConnect -=
                new VoiceGateway.DaemonCouldntConnectCallback(connector_OnDaemonCouldntConnect);
            OnAuxAudioPropertiesEvent -=
                new EventHandler <AudioPropertiesEventArgs>(connector_OnAuxAudioPropertiesEvent);

            // Session events
            OnSessionStateChangeEvent -=
                new EventHandler <SessionStateChangeEventArgs>(connector_OnSessionStateChangeEvent);
            OnSessionAddedEvent -=
                new EventHandler <SessionAddedEventArgs>(connector_OnSessionAddedEvent);

            // Session Participants events
            OnSessionParticipantUpdatedEvent -=
                new EventHandler <ParticipantUpdatedEventArgs>(connector_OnSessionParticipantUpdatedEvent);
            OnSessionParticipantAddedEvent -=
                new EventHandler <ParticipantAddedEventArgs>(connector_OnSessionParticipantAddedEvent);
            OnSessionParticipantRemovedEvent -=
                new EventHandler <ParticipantRemovedEventArgs>(connector_OnSessionParticipantRemovedEvent);

            // Tuning events
            OnAuxGetCaptureDevicesResponse -=
                new EventHandler <VoiceGateway.VoiceDevicesEventArgs>(connector_OnAuxGetCaptureDevicesResponse);
            OnAuxGetRenderDevicesResponse -=
                new EventHandler <VoiceGateway.VoiceDevicesEventArgs>(connector_OnAuxGetRenderDevicesResponse);

            // Account events
            OnAccountLoginResponse -=
                new EventHandler <VoiceGateway.VoiceAccountEventArgs>(connector_OnAccountLoginResponse);

            // Stop the background thread
            if (posThread != null)
            {
                PosUpdating(false);

                if (posThread.IsAlive)
                {
                    posThread.Abort();
                }
                posThread = null;
            }

            // Close all sessions
            foreach (VoiceSession s in sessions.Values)
            {
                if (OnSessionRemove != null)
                {
                    OnSessionRemove(s, EventArgs.Empty);
                }
                s.Close();
            }

            // Clear out lots of state so in case of restart we begin at the beginning.
            currentParcelCap = null;
            sessions.Clear();
            accountHandle = null;
            voiceUser     = null;
            voicePassword = null;

            SessionTerminate(sessionHandle);
            sessionHandle = null;
            AccountLogout(accountHandle);
            accountHandle = null;
            ConnectorInitiateShutdown(connectionHandle);
            connectionHandle = null;
            StopDaemon();
        }
        public void Stop()
        {
            Client.Network.EventQueueRunning -= new EventHandler<EventQueueRunningEventArgs>(Network_EventQueueRunning);

            // Connection events
            OnDaemonRunning -=
                     new VoiceGateway.DaemonRunningCallback(connector_OnDaemonRunning);
            OnDaemonCouldntRun -=
                    new VoiceGateway.DaemonCouldntRunCallback(connector_OnDaemonCouldntRun);
            OnConnectorCreateResponse -=
                new EventHandler<VoiceGateway.VoiceConnectorEventArgs>(connector_OnConnectorCreateResponse);
            OnDaemonConnected -=
                    new VoiceGateway.DaemonConnectedCallback(connector_OnDaemonConnected);
            OnDaemonCouldntConnect -=
                    new VoiceGateway.DaemonCouldntConnectCallback(connector_OnDaemonCouldntConnect);
            OnAuxAudioPropertiesEvent -=
                    new EventHandler<AudioPropertiesEventArgs>(connector_OnAuxAudioPropertiesEvent);

            // Session events
            OnSessionStateChangeEvent -=
                    new EventHandler<SessionStateChangeEventArgs>(connector_OnSessionStateChangeEvent);
            OnSessionAddedEvent -=
                    new EventHandler<SessionAddedEventArgs>(connector_OnSessionAddedEvent);

            // Session Participants events
            OnSessionParticipantUpdatedEvent -=
                    new EventHandler<ParticipantUpdatedEventArgs>(connector_OnSessionParticipantUpdatedEvent);
            OnSessionParticipantAddedEvent -=
                    new EventHandler<ParticipantAddedEventArgs>(connector_OnSessionParticipantAddedEvent);
            OnSessionParticipantRemovedEvent -=
                    new EventHandler<ParticipantRemovedEventArgs>(connector_OnSessionParticipantRemovedEvent);

            // Tuning events
            OnAuxGetCaptureDevicesResponse -=
                    new EventHandler<VoiceGateway.VoiceDevicesEventArgs>(connector_OnAuxGetCaptureDevicesResponse);
            OnAuxGetRenderDevicesResponse -=
                    new EventHandler<VoiceGateway.VoiceDevicesEventArgs>(connector_OnAuxGetRenderDevicesResponse);

            // Account events
            OnAccountLoginResponse -=
                    new EventHandler<VoiceGateway.VoiceAccountEventArgs>(connector_OnAccountLoginResponse);

            // Stop the background thread
            if (posThread != null)
            {
                PosUpdating(false);

                if (posThread.IsAlive)
                    posThread.Abort();
                posThread = null;
            }

            // Close all sessions
            foreach (VoiceSession s in sessions.Values)
            {
                if (OnSessionRemove != null)
                    OnSessionRemove(s, EventArgs.Empty);
                s.Close();
            }

            // Clear out lots of state so in case of restart we begin at the beginning.
            currentParcelCap = null;
            sessions.Clear();
            accountHandle = null;
            voiceUser = null;
            voicePassword = null;

            SessionTerminate(sessionHandle);
            sessionHandle = null;
            AccountLogout(accountHandle);
            accountHandle = null;
            ConnectorInitiateShutdown(connectionHandle);
            connectionHandle = null;
            StopDaemon();
        }