How to detect that the phone (WP7) has stopped shaking
I can get the phone to react to a shake, bu开发者_开发技巧t what is the best way to tell that it has stopped shaking?
This example worked for me.
At the very bottom of the page you'll see:
if (!_shaking && CheckForShake(_lastReading, reading, ShakeThreshold) && _shakeCount >= 1)
{
//We are shaking
_shaking = true;
_shakeCount = 0;
OnShakeDetected();
}
else if (CheckForShake(_lastReading, reading, ShakeThreshold))
{
_shakeCount++;
}
else if (!CheckForShake(_lastReading, reading, 0.2))
{
_shakeCount = 0;
_shaking = false;
}
Do like #Daniel Pereira said, but in the void ShakeDetected(object sender, EventArgs e) use a Dispatcher.BeginInvoke(() => youMethod()); and do what you pretend to do in youMethod(). I know this post is a little old but now other people can know how it resolve
精彩评论