summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJason Smith <jason.smith@xamarin.com>2016-05-27 04:47:22 -0700
committerRui Marinho <me@ruimarinho.net>2016-05-27 15:42:37 +0100
commit2a09b3952d090ccc6f3bc2006db0ce3c84d95520 (patch)
tree6a756f5bb2a4dac961558cf0dcfbfb309ad4f60e
parent4b30cb45b86a5768b3dd8e7279e44e0bc77f4b4e (diff)
downloadxamarin-forms-beta-2.3.0-pre3.tar.gz
xamarin-forms-beta-2.3.0-pre3.tar.bz2
xamarin-forms-beta-2.3.0-pre3.zip
Fix android StartTimer race condition (#196)beta-2.3.0-pre3
-rw-r--r--Xamarin.Forms.Platform.Android/Forms.cs19
1 files changed, 13 insertions, 6 deletions
diff --git a/Xamarin.Forms.Platform.Android/Forms.cs b/Xamarin.Forms.Platform.Android/Forms.cs
index 2699241f..62e07f22 100644
--- a/Xamarin.Forms.Platform.Android/Forms.cs
+++ b/Xamarin.Forms.Platform.Android/Forms.cs
@@ -361,13 +361,20 @@ namespace Xamarin.Forms
public void StartTimer(TimeSpan interval, Func<bool> callback)
{
Timer timer = null;
- TimerCallback onTimeout = o => BeginInvokeOnMainThread(() =>
+ bool invoking = false;
+ TimerCallback onTimeout = o =>
{
- if (callback())
- return;
-
- timer.Dispose();
- });
+ if (!invoking)
+ {
+ invoking = true;
+ BeginInvokeOnMainThread(() =>
+ {
+ if (!callback())
+ timer.Dispose();
+ invoking = false;
+ });
+ }
+ };
timer = new Timer(onTimeout, null, interval, interval);
}