Created
June 30, 2017 01:47
-
-
Save markjulmar/5a8d8f94b44c7c4e5a2a751416f9476e to your computer and use it in GitHub Desktop.
Show DisplayAlert from background thread.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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")); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code works properly in release and debug builds. If you remove the
BeginInvokeOnMainThread
it dies a horrible death.