I am recieving the System.InvalidOperationException

I have a voice activated program that is throwing the only error. Its a System.InvalidOperationException I have tried numerous methods and I can not figure out why it is not being corrected.


I am using System.Speech. I have a timer and in the timer, i have it enabled and disabled it from True to False and False to True. Neither of it fixes the issue.



i have declared my Class

SpeechRecognitionEngine startlistening = new SpeechRecognitionEngine();


I have specified my Events



startlistening.SetInputToDefaultAudioDevice();
startlistening.LoadGrammarAsync(new Grammar(new GrammarBuilder(new Choices("alexis"))));
startlistening.SpeechRecognized += new EventHandler<SpeechRecognizedEventArgs>(startlistening_SpeechRecognized);


and then I have placed the command



case "quit listening":
Alexis.SpeakAsync("I will await further commands ");
_recognizer.RecognizeAsyncCancel();
startlistening.RecognizeAsync(RecognizeMode.Multiple);
break;


then i have placed my timer



private void tmrSpeech_Tick(object sender, EventArgs e)
{
if (recTimeOut == 10)
{
_recognizer.RecognizeAsyncCancel();
}
else if (recTimeOut == 11)
{
startlistening.RecognizeAsync(RecognizeMode.Multiple);
tmrSpeech.Stop();
recTimeOut = 0;
}
recTimeOut += 1;
}


I have declared the struct for Start listening



void startlistening_SpeechRecognized(object sender, SpeechRecognizedEventArgs e)
{

string speech = e.Result.Text;
switch (speech)
{
case "alexis":
startlistening.RecognizeAsyncCancel();
Alexis.SpeakAsync("I am back online");
_recognizer.RecognizeAsync(RecognizeMode.Multiple);
break;
}
}


I am at a loss. I have all references set, as well as the timer set on


Enabled False Interval 10000 GenerateMember True Modifiers Private


Could there be something i am missing. When i tell the program to Quit Listening it uses the AsyncCancel and then if say Alexis then the program responds with no errors. However if i say Quit Listening and wait longer than 10 seconds it will throw the Exception. I have tried everything i know to do. Any Ideas? I am using Visual Studio 2013 Community and its in Winforms and .NET 4.5 Framework