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

Commit 8f8625d

Browse files
Jason Smithrmarinho
authored andcommitted
Fix android StartTimer race condition (#196)
1 parent 33a4604 commit 8f8625d

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
@@ -380,13 +380,20 @@ public void OpenUriAction(Uri uri)
380380
public void StartTimer(TimeSpan interval, Func<bool> callback)
381381
{
382382
Timer timer = null;
383-
TimerCallback onTimeout = o => BeginInvokeOnMainThread(() =>
383+
bool invoking = false;
384+
TimerCallback onTimeout = o =>
384385
{
385-
if (callback())
386-
return;
387-
388-
timer.Dispose();
389-
});
386+
if (!invoking)
387+
{
388+
invoking = true;
389+
BeginInvokeOnMainThread(() =>
390+
{
391+
if (!callback())
392+
timer.Dispose();
393+
invoking = false;
394+
});
395+
}
396+
};
390397
timer = new Timer(onTimeout, null, interval, interval);
391398
}
392399

0 commit comments

Comments
 (0)