S
Scott Gifford
Hello,
I'm doing a notification beep from a device that's asleep (it's
receiving a network notification). To do this, I put the device into
unattended mode, request the "WAV1:" device, play the sound, then
release WAV1: and leave unattended mode.
This basically works, but the request for WAV1: seems to return before
the device is ready, and SystemSounds.Beep.Play() also returns before
the sound is done playing. To compensate for this, I use
Thread.Sleep() statements. This works, but seems error-prone. For
example, I imagine the time it takes to wake up the sound device
varies between handhelds, and the user's sytem beep could be longer
than my sleep (which could cut it off) or shoter (which is better, but
will still waste power).
I was wondering first if this is how it's supposed to work, or if I
might be doing something wrong? If so, is there was a way to request
a device synchronously, and a way to play a system sound
synchronously? Or maybe to receive a notification when these events
are complete?
Here is my code. I've modified it slightly to make it clearer, please
excuse any typoes. Some of the code is P/Invokes implemented in my
classes PowerPolicy and PowerHelper, implemented in the obvious ways.
PowerPolicy.PowerPolicyNotify(PowerPolicy.PPN_UNATTENDEDMODE, 1);
try
{
IntPtr pwrHandle = PowerHelper.SetPowerRequirement("WAV1:",
PowerHelper.CEDEVICE_POWER_STATE.D0,
PowerHelper.POWER_NAME | PowerHelper.POWER_FORCE,
null, 0);
if (pwrHandle == null)
throw new Exception("Error requesting WAV1 power on: " + Marshal.GetLastWin32Error());
try
{
// Give the device a second to wake up
System.Threading.Thread.Sleep(1000);
OpenNETCF.Media.SystemSounds.Beep.Play();
// Wait a few seconds for the sound to stop
// playing before powering off the device.
System.Threading.Thread.Sleep(5000);
}
finally
{
powerSound.Release();
}
}
finally
{
PowerPolicy.stopUnattendedMode();
}
Thanks for any help or advice!
----Scott.
I'm doing a notification beep from a device that's asleep (it's
receiving a network notification). To do this, I put the device into
unattended mode, request the "WAV1:" device, play the sound, then
release WAV1: and leave unattended mode.
This basically works, but the request for WAV1: seems to return before
the device is ready, and SystemSounds.Beep.Play() also returns before
the sound is done playing. To compensate for this, I use
Thread.Sleep() statements. This works, but seems error-prone. For
example, I imagine the time it takes to wake up the sound device
varies between handhelds, and the user's sytem beep could be longer
than my sleep (which could cut it off) or shoter (which is better, but
will still waste power).
I was wondering first if this is how it's supposed to work, or if I
might be doing something wrong? If so, is there was a way to request
a device synchronously, and a way to play a system sound
synchronously? Or maybe to receive a notification when these events
are complete?
Here is my code. I've modified it slightly to make it clearer, please
excuse any typoes. Some of the code is P/Invokes implemented in my
classes PowerPolicy and PowerHelper, implemented in the obvious ways.
PowerPolicy.PowerPolicyNotify(PowerPolicy.PPN_UNATTENDEDMODE, 1);
try
{
IntPtr pwrHandle = PowerHelper.SetPowerRequirement("WAV1:",
PowerHelper.CEDEVICE_POWER_STATE.D0,
PowerHelper.POWER_NAME | PowerHelper.POWER_FORCE,
null, 0);
if (pwrHandle == null)
throw new Exception("Error requesting WAV1 power on: " + Marshal.GetLastWin32Error());
try
{
// Give the device a second to wake up
System.Threading.Thread.Sleep(1000);
OpenNETCF.Media.SystemSounds.Beep.Play();
// Wait a few seconds for the sound to stop
// playing before powering off the device.
System.Threading.Thread.Sleep(5000);
}
finally
{
powerSound.Release();
}
}
finally
{
PowerPolicy.stopUnattendedMode();
}
Thanks for any help or advice!
----Scott.