Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

Commit

Permalink
Fix android StartTimer race condition (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jason Smith authored and rmarinho committed May 27, 2016
1 parent 4b30cb4 commit 2a09b39
Showing 1 changed file with 13 additions and 6 deletions.
19 changes: 13 additions & 6 deletions Xamarin.Forms.Platform.Android/Forms.cs
Expand Up @@ -361,13 +361,20 @@ public void OpenUriAction(Uri uri)
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);
}

Expand Down

0 comments on commit 2a09b39

Please sign in to comment.