SpeechRecognitionEngine.UnloadGrammar Method

Unloads a grammar, as specified by an instance of Grammar, from an instance of SpeechRecognitionEngine.

Namespace: Microsoft.Speech.Recognition
Assembly: Microsoft.Speech (in microsoft.speech.dll)




  • grammar
    An instance of Grammar specify the grammar to remove from an instance of SpeechRecognitionEngine.


If the Grammar specified by the grammar parameter is not currently loaded, TargetInvocationException will be generated.


The example below shows the atomic, synchronous loading and the unloading of instances of Grammar on a running SpeechRecognitionEngine by an anonymous method that handling RecognizerUpdateReached events, based on the user token custom object (GrammarRequest) supplied to the method.

recognizer.RecognizerUpdateReached +=
       delegate(object s, RecognizerUpdateReachedEventArgs args) {
           GrammarRequest request = args.UserToken as GrammarRequest; //cast and check if incoming type is a request
           if (request != null) { // We know this is a Grammar request now
               if (request.Grammar == null)
                   throw new ArgumentException("Invalid grammar used.");
           switch (request.RequestType) {

               case GrammarRequestType.LoadGrammar:
               case GrammarRequestType.UnloadGrammar:
                   UpdateGrammarTree(_grammarTreeView, _recognizer);



Thread Safety

All public static (Shared in Visual Basic) members of this type are thread-safe. Instance members are not guaranteed to be thread-safe.


Development Platforms

Windows XP Professional with Service Pack 2 (SP2), Windows Server 2003, Windows Vista Ultimate Edition, Windows Vista Business Edition, Windows Vista Enterprise Edition

Target Platforms

See Also


SpeechRecognitionEngine Class
SpeechRecognitionEngine Members
Microsoft.Speech.Recognition Namespace
SpeechRecognitionEngine.LoadGrammarAsync Method
SpeechRecognitionEngine.LoadGrammarAsync Method