开发者

How to detect that the phone (WP7) has stopped shaking

开发者 https://www.devze.com 2023-04-03 12:45 出处:网络
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.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消