Skip to content

Instantly share code, notes, and snippets.

@markjulmar
Created June 30, 2017 01:47
Show Gist options
  • Save markjulmar/5a8d8f94b44c7c4e5a2a751416f9476e to your computer and use it in GitHub Desktop.
Save markjulmar/5a8d8f94b44c7c4e5a2a751416f9476e to your computer and use it in GitHub Desktop.
Show DisplayAlert from background thread.
private void Button_Clicked(object sender, EventArgs e)
{
Task.Run(() => OnShowAlert("Hello"));
}
private void OnShowAlert(string text)
{
string title = $"OnShowAlert tid={Environment.CurrentManagedThreadId}";
Device.BeginInvokeOnMainThread(
async () => await DisplayAlert(title, text, "OK"));
}
@markjulmar
Copy link
Author

This code works properly in release and debug builds. If you remove the BeginInvokeOnMainThread it dies a horrible death.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment