diff options
author | Jason Smith <jason.smith@xamarin.com> | 2016-05-27 04:47:22 -0700 |
---|---|---|
committer | Rui Marinho <me@ruimarinho.net> | 2016-05-27 12:47:22 +0100 |
commit | bf7399d06815d906bde609e23ad48faa452390f0 (patch) | |
tree | 86fea16ca36ef1230cf02c6b899831c071785ba3 | |
parent | 2e75020b0ff028c70920074f32b996ead3a8f2bb (diff) | |
download | xamarin-forms-bf7399d06815d906bde609e23ad48faa452390f0.tar.gz xamarin-forms-bf7399d06815d906bde609e23ad48faa452390f0.tar.bz2 xamarin-forms-bf7399d06815d906bde609e23ad48faa452390f0.zip |
Fix android StartTimer race condition (#196)
-rw-r--r-- | Xamarin.Forms.Platform.Android/Forms.cs | 19 |
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); } |