/// <summary>
        /// Starts service
        /// </summary>
        protected override void Start()
        {
            try
            {
                if (_state == null)
                {
                    _state = new SpeechRecognizerState();
                }

                // Set up speech recognition engine
                if (_state.IgnoreAudioInput)
                {
                    _state.Recognizer.SetInputToNull();
                }
                else
                {
                    _state.Recognizer.SetInputToDefaultAudioDevice();
                }

                // Register event handlers for speech recognition
                _state.Recognizer.RecognizerUpdateReached   += RecognizerUpdateReachedHandler;
                _state.Recognizer.LoadGrammarCompleted      += LoadGrammarCompletedHandler;
                _state.Recognizer.SpeechDetected            += SpeechDetectedHandler;
                _state.Recognizer.SpeechRecognized          += SpeechRecognizedHandler;
                _state.Recognizer.SpeechRecognitionRejected += SpeechRecognitionRejectedHandler;
            }
            catch (Exception exception)
            {
                // Fatal exception during startup, shutdown service
                LogError(LogGroups.Activation, exception);
                _state.Recognizer.Dispose();
                DefaultDropHandler(new DsspDefaultDrop());
                return;
            }

            SpawnIterator(LoadGrammarOnStartup);
        }
        public IEnumerator <ITask> ReplaceHandler(Replace replace)
        {
            SpeechRecognizerState newState = replace.Body;

            #region Set up load grammar request, load grammar and on success store new grammar in state
            // Set up load grammar request
            LoadGrammarRequest loadRequest = new LoadGrammarRequest();
            loadRequest.GrammarType       = newState.GrammarType;
            loadRequest.SrgsFileLocation  = newState.SrgsFileLocation;
            loadRequest.DictionaryGrammar = newState.DictionaryGrammar;

            // Load new grammar
            SuccessFailurePort loadGrammarPort = new SuccessFailurePort();
            SpawnIterator <LoadGrammarRequest, SuccessFailurePort>(
                loadRequest,
                loadGrammarPort,
                LoadGrammar
                );

            // Check loading outcome
            yield return((Choice)loadGrammarPort);

            Exception exception = (Exception)loadGrammarPort;
            if (exception != null)
            {
                LogWarning(exception);
                replace.ResponsePort.Post(Fault.FromCodeSubcodeReason(
                                              W3C.Soap.FaultCodes.Receiver,
                                              DsspFaultCodes.OperationFailed,
                                              exception.Message
                                              ));
                yield break;
            }
            #endregion

            #region Check new state's IgnoreAudioInput flag and start recognition engine if necessary
            if (newState.IgnoreAudioInput != _state.IgnoreAudioInput)
            {
                _state.IgnoreAudioInput = newState.IgnoreAudioInput;
                if (_state.IgnoreAudioInput)
                {
                    // Stop engine and switch to ignoring audio input
                    _state.Recognizer.RecognizeAsyncCancel();
                    _state.Recognizer.SetInputToNull();
                }
                else
                {
                    _state.Recognizer.SetInputToDefaultAudioDevice();

                    // Because old state ignored audio input the engine is stopped, now that
                    // we switched to listening to audio input the engine needs to be started
                    if (_state.Recognizer.Grammars.Count > 0)
                    {
                        _state.Recognizer.RecognizeAsync(RecognizeMode.Multiple);
                    }
                }
            }
            #endregion

            SaveState(_state);

            // Notify subscribers of state change
            replace.Body = _state;
            SendNotification <Replace>(_subMgrPort, replace);

            replace.ResponsePort.Post(DefaultReplaceResponseType.Instance);
        }