SpeechRecognitionEngine.UnloadGrammar Method
Unloads a grammar, as specified by an instance of Grammar, from an instance of SpeechRecognitionEngine.
Assembly: System.Speech (in System.Speech.dll)
Parameters
- grammar
- Type: System.Speech.Recognition.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:
RemoveDuplicateGrammar(request.Grammar);
_recognizer.LoadGrammar(request.Grammar);
break;
case GrammarRequestType.UnloadGrammar:
_recognizer.UnloadGrammar(request.Grammar);
UpdateGrammarTree(_grammarTreeView, _recognizer);
//DisplayGrammarUnload(request.Grammar);
break;
}
};
}
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see Using Libraries from Partially Trusted Code.
Windows 7, Windows Vista, Windows XP SP2, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003
The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.