Can't enable a Timer in a Speech Recognized handler

P

Peter Oliphant

YEAH! Indeed, everyone in this newsgroup pointed (ok pushed..hehe) me into
the right direction.

If I use this Timer:

System::Timers::Timer it all works.

If I use:

System::Windows::Form::Timer it doesn't.

Only difference in implementation is one uses a Tick event the other an
Elapsed event (and corresponding different event hadler forms ala different
argument types). Mixing managed and unmanaged can have some unpredictable
side-effects!

And I think this might solve another problem I just realized could be
related!

Thanx everyone. It works now...

[==Peter==]
Peter Oliphant said:
I've been using System::Windows::Forms::Timer, which doesn't have an
'InvokeRequired' property.

I'm thinking I'm using the wrong Timer class. I'll look for others in
MSDN. Not sure how to look up different classes with the same name though.
The one I use isn't managed. I'd rather use a managed one, as long as it
can have an Interval in milliseconds, a means to turn it on and off, and a
way to give it an event handler (hopefully via delegates).

Not sure that has anything to do with it, but it could...

[==Peter==]

Ben Voigt said:
Peter Oliphant said:
What if you enable the Timer before starting recognition? Do ticks
stop arriving when you enable the recognition engine?

The Timer runs fine unless I try to use it in the event handler. That
is, any running Timer is not effected by the recognition event handler
firing, but trying to do something with a Timer inside such a handler
does.

Could your tick handler check a shared variable and immediately return
in order to emulate disabling the timer?

Indeed, this is how I do it. But of course this isn't as immediate, but
so far works for my purposes. While this is a 'work around' that works,
it still seems odd that one can't launch (i.e., enable successfully) a
Timer inside recognition handlers. If this is a bug, I'd rather not have
to create the delayed infostructure I have and enable the Timer
directly. If this is a 'feature' (ala it is intended behaviour), then
I'll stick with the work around.

Could you print out the value of the InvokeRequired property of your
timer, seen inside the recognition handler?
[==Peter==]
 
P

Peter Oliphant

I reported success a bit too soon.

It worked in the simple case. But I'm seeing a lot of thread conflicts
(Output messages) now. And a LOT more is being loaded in at startup.

I think I'm running into conflicts between the voice recognition engine SAPI
and the Timers. Or they are somehow interfering with themselves (my simple
case only had one timer that went when voice recognition was done). I'll
keep experimenting...

[==Peter==]

Peter Oliphant said:
YEAH! Indeed, everyone in this newsgroup pointed (ok pushed..hehe) me into
the right direction.

If I use this Timer:

System::Timers::Timer it all works.

If I use:

System::Windows::Form::Timer it doesn't.

Only difference in implementation is one uses a Tick event the other an
Elapsed event (and corresponding different event hadler forms ala
different argument types). Mixing managed and unmanaged can have some
unpredictable side-effects!

And I think this might solve another problem I just realized could be
related!

Thanx everyone. It works now...

[==Peter==]
Peter Oliphant said:
I've been using System::Windows::Forms::Timer, which doesn't have an
'InvokeRequired' property.

I'm thinking I'm using the wrong Timer class. I'll look for others in
MSDN. Not sure how to look up different classes with the same name
though. The one I use isn't managed. I'd rather use a managed one, as
long as it can have an Interval in milliseconds, a means to turn it on
and off, and a way to give it an event handler (hopefully via delegates).

Not sure that has anything to do with it, but it could...

[==Peter==]

Ben Voigt said:
What if you enable the Timer before starting recognition? Do ticks
stop arriving when you enable the recognition engine?

The Timer runs fine unless I try to use it in the event handler. That
is, any running Timer is not effected by the recognition event handler
firing, but trying to do something with a Timer inside such a handler
does.

Could your tick handler check a shared variable and immediately return
in order to emulate disabling the timer?

Indeed, this is how I do it. But of course this isn't as immediate, but
so far works for my purposes. While this is a 'work around' that works,
it still seems odd that one can't launch (i.e., enable successfully) a
Timer inside recognition handlers. If this is a bug, I'd rather not
have to create the delayed infostructure I have and enable the Timer
directly. If this is a 'feature' (ala it is intended behaviour), then
I'll stick with the work around.

Could you print out the value of the InvokeRequired property of your
timer, seen inside the recognition handler?


[==Peter==]
 
P

Peter Oliphant

Sorry for all the messages, but I think I FINALLY have it all sorted out.

I have to use System::Windows::Form::Timer class timers if their handlers
will manipulate controls and graphics on Forms.

I must use System::Timeers::Timer class timers if I want to launch Speech
Recognition from their event handlers.

You can see how this was confusing, especially since they have the same name
and almost the same structure (but thank goodness for the last one,
conversion was easier because of it).

I now have my own Timer class that uses which ever type, defined upon
creation (poiner to both types internally, use only one for any instance).

As always, I learned a LOT about stuff this way!!! :)

[==Peter==]
Peter Oliphant said:
I reported success a bit too soon.

It worked in the simple case. But I'm seeing a lot of thread conflicts
(Output messages) now. And a LOT more is being loaded in at startup.

I think I'm running into conflicts between the voice recognition engine
SAPI and the Timers. Or they are somehow interfering with themselves (my
simple case only had one timer that went when voice recognition was done).
I'll keep experimenting...

[==Peter==]

Peter Oliphant said:
YEAH! Indeed, everyone in this newsgroup pointed (ok pushed..hehe) me
into the right direction.

If I use this Timer:

System::Timers::Timer it all works.

If I use:

System::Windows::Form::Timer it doesn't.

Only difference in implementation is one uses a Tick event the other an
Elapsed event (and corresponding different event hadler forms ala
different argument types). Mixing managed and unmanaged can have some
unpredictable side-effects!

And I think this might solve another problem I just realized could be
related!

Thanx everyone. It works now...

[==Peter==]
Peter Oliphant said:
I've been using System::Windows::Forms::Timer, which doesn't have an
'InvokeRequired' property.

I'm thinking I'm using the wrong Timer class. I'll look for others in
MSDN. Not sure how to look up different classes with the same name
though. The one I use isn't managed. I'd rather use a managed one, as
long as it can have an Interval in milliseconds, a means to turn it on
and off, and a way to give it an event handler (hopefully via
delegates).

Not sure that has anything to do with it, but it could...

[==Peter==]


What if you enable the Timer before starting recognition? Do ticks
stop arriving when you enable the recognition engine?

The Timer runs fine unless I try to use it in the event handler. That
is, any running Timer is not effected by the recognition event handler
firing, but trying to do something with a Timer inside such a handler
does.

Could your tick handler check a shared variable and immediately return
in order to emulate disabling the timer?

Indeed, this is how I do it. But of course this isn't as immediate,
but so far works for my purposes. While this is a 'work around' that
works, it still seems odd that one can't launch (i.e., enable
successfully) a Timer inside recognition handlers. If this is a bug,
I'd rather not have to create the delayed infostructure I have and
enable the Timer directly. If this is a 'feature' (ala it is intended
behaviour), then I'll stick with the work around.

Could you print out the value of the InvokeRequired property of your
timer, seen inside the recognition handler?


[==Peter==]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top