OK, I've duplicated the problem in a little bit of code. I've put it
below, you must excuse any line-wrap.
If you want to see, create a console project.Place the code I have below
the Project.CPP file (the one with main()).
Be sure to add System.Speech as a reference, and set it up tp target .NET
Framework 3.5. This code will also likely only work on a Windows VISTA
machine (SAPI 5.3).
Describing the code:
In a 'globals' class it creates a Timer and a SpeechRecognitionEngine
(that recognizes 'yes' or 'no'). Say 'yes' or 'no' into the microphone,
and he Engine's Completed handler writes 'enable timer' to the console and
enables the timer. The Timer should after that write 'tick!' to the
display 4 times a second after that.
What happens is that you will see the 'enable timer' message, proving the
Completed handler fired and enabled Timer, but the 'Tick's never show up
indicating the Timer never fires!
Thus, whether a restriction or a bug, a Timer can't be enabled
successfully in any Speech Recognition event handler (this happens with
all of them, I'm just demonstrting Completed here).
Here is the code:
//------------------------
#include "stdafx.h"
#using <mscorlib.dll>
#using <System.DLL>
#using <System.Windows.Forms.DLL>
using namespace System::Windows::Forms ;
using namespace System ;
using namespace System::Speech::Recognition ;
typedef EventHandler<RecognizeCompletedEventArgs^>
Speech_Completed_Handler ;
typedef System::Windows::Forms::Timer System_Timer ;
ref class globals
{
public:
static globals()
{
Timer = gcnew System::Windows::Forms::Timer() ;
Timer->Tick += gcnew EventHandler(&globals::Tick_Handler ) ;
Timer->Interval = 100 ;
Engine = gcnew SpeechRecognitionEngine() ;
Engine->SetInputToDefaultAudioDevice() ;
Engine->RecognizeCompleted += gcnew Speech_Completed_Handler(
&globals::Completed_Handler ) ;
Choices^ choices = gcnew Choices ;
choices->Add( "yes" ) ;
choices->Add("no" ) ;
Grammar^ grammar = gcnew Grammar(choices) ;
Engine->LoadGrammar(grammar) ;
}
static void Completed_Handler(Object^,RecognizeCompletedEventArgs^)
{
Console::WriteLine( "enable timer" ) ;
Timer->Enabled = true ;
}
static void Tick_Handler( System::Object^,EventArgs^ )
{
Console::WriteLine( "tick!" ) ;
}
static SpeechRecognitionEngine^ Engine ;
static System::Windows::Forms::Timer^ Timer ;
} ;
int main(array<System::String ^> ^args)
{
Console::WriteLine("Speak!");
globals::Engine->RecognizeAsync() ;
Form^ form = gcnew Form() ;
Application::Run( form ) ;
return 0;
}
//------------------------
[==Peter==]
Ben Voigt said:
Which "Timer"? .NET has at least three different classes named Timer.