Hi,
I am writing a small console application in which I instantiate a new
object and add an event listener to it. My goal is now to wait and sit
there until such an event occurs, in which case my listener gets called.
My problem is: how do I implement that? Clearly, if I just add my
listener to the object, my program will terminate after that. It seems
that adding an infinite loop after that doesn't work (blocking?), so I
was thinking of using threads. My initial attempt didn't prove
successful, though.
Anybody knows how to do this? It's a very unambitious goal and I am
sure there must be a way. By the way, it's about Microsoft Speech API
(SAPI) and the event listener here is the callback function that is
called whenever sth was recognized.
Here is the code skeleton:
class Program {
// Declaration for variables
...
public void init()
{
//Initialize object
objRecoContext = new SpeechLib.SpSharedRecoContext();
...
// Add listener
objRecoContext.Recognition += new
_ISpeechRecoContextEvents_RecognitionEventHandler(handleRecognition);
}
public void handleRecognition(...)
{
System.console.WriteLine("Got it");
}
public static void Main()
{
Program p = new Program();
p.init();
}
}
I would be really glad for any help.
Thanks!