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

Commit 2a09b39

Browse files
Jason Smithrmarinho
authored andcommitted
Fix android StartTimer race condition (#196)
1 parent 4b30cb4 commit 2a09b39

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

Xamarin.Forms.Platform.Android/Forms.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -361,13 +361,20 @@ public void OpenUriAction(Uri uri)
361361
public void StartTimer(TimeSpan interval, Func<bool> callback)
362362
{
363363
Timer timer = null;
364-
TimerCallback onTimeout = o => BeginInvokeOnMainThread(() =>
364+
bool invoking = false;
365+
TimerCallback onTimeout = o =>
365366
{
366-
if (callback())
367-
return;
368-
369-
timer.Dispose();
370-
});
367+
if (!invoking)
368+
{
369+
invoking = true;
370+
BeginInvokeOnMainThread(() =>
371+
{
372+
if (!callback())
373+
timer.Dispose();
374+
invoking = false;
375+
});
376+
}
377+
};
371378
timer = new Timer(onTimeout, null, interval, interval);
372379
}
373380

0 commit comments

Comments
 (0)