B
Brian H
Hi all,
I've spent a couple of hours to observe this behavior... In my app, I have
an option that, if selected, spawns a new thread, and waits for the top of
the hour to play a sound. I wait for this event with something like:
Result = WaitForSingleObject(ExitEvent, WaitMilliseconds)
If you disable this option -- or if the app is exited -- I raise the exit
event (courtesy of OpenNetCF SetEvent) to exit the thread. This works fine.
But I've since added a bunch of options that may change the fequency of when
this sound plays. For example, perhaps it will play every 10 minutes,
instead of the top of the hour. So when this property is set based on user
input, this first thing I always do is force the thread to exit by pulsing
the event:
OpenNETCF.Win32.Core.SetEvent(ExitEvent)
The property set then evaluates the current state of various options, then
respawns the thread. The idea here is that, if the app is waiting until the
top of the hour to do something, but now I want it to go off in 5 minutes, I
want to abort, then reset the thread.
The crux of the problem is that if I pulse the ExitEvent, then immediately
spawn the new thread, I'm seeing inconsistent behavior in the thread exiting
before it gets respawned. So more or less, I've done something like this:
OpenNETCF.Win32.Core.SetEvent(ExitEvent)
Thread.Sleep(250)
If Value = true or (other evaluations here) Then
WaitThread = New Thread(AddressOf WaitForNextChime)
WaitThread.Start()
End If
By adding the thread.sleep, I'm now seeing the thread is always exiting
before getting respawned. 250 may be too high a value, but I'm looking for
feedback on this. Without the thread.sleep, sometimes the thread exits
first, sometimes it doesn't.
Thanks for any feedback!
Brian
I've spent a couple of hours to observe this behavior... In my app, I have
an option that, if selected, spawns a new thread, and waits for the top of
the hour to play a sound. I wait for this event with something like:
Result = WaitForSingleObject(ExitEvent, WaitMilliseconds)
If you disable this option -- or if the app is exited -- I raise the exit
event (courtesy of OpenNetCF SetEvent) to exit the thread. This works fine.
But I've since added a bunch of options that may change the fequency of when
this sound plays. For example, perhaps it will play every 10 minutes,
instead of the top of the hour. So when this property is set based on user
input, this first thing I always do is force the thread to exit by pulsing
the event:
OpenNETCF.Win32.Core.SetEvent(ExitEvent)
The property set then evaluates the current state of various options, then
respawns the thread. The idea here is that, if the app is waiting until the
top of the hour to do something, but now I want it to go off in 5 minutes, I
want to abort, then reset the thread.
The crux of the problem is that if I pulse the ExitEvent, then immediately
spawn the new thread, I'm seeing inconsistent behavior in the thread exiting
before it gets respawned. So more or less, I've done something like this:
OpenNETCF.Win32.Core.SetEvent(ExitEvent)
Thread.Sleep(250)
If Value = true or (other evaluations here) Then
WaitThread = New Thread(AddressOf WaitForNextChime)
WaitThread.Start()
End If
By adding the thread.sleep, I'm now seeing the thread is always exiting
before getting respawned. 250 may be too high a value, but I'm looking for
feedback on this. Without the thread.sleep, sometimes the thread exits
first, sometimes it doesn't.
Thanks for any feedback!
Brian