I have a custom dialog and it’s being created by the code below:
public DialogFragment CreateNewPostedMessageDialog(CardSwipeData data,
List<MessagesMap> messagesMap,
string fbProfileimageAsByteString,
Context context) {
DialogFragment newFragment =
new NewPostedMessageDialogFragment(data, messagesMap,
fbProfileimageAsByteString,
context);
return newFragment;
}
It’s called from my Activity’s OnResume RunOnUiThread:
ThreadPool.QueueUserWorkItem(state => {
// Processing stuff here
RunOnUiThread(() => {
DialogFragment dialog = CreateNewPostedMessageDialog(cardSwipeData,
messagesMap, bitmapByteString, this);
dialog.Show(FragmentManager, "PostedMessage");
// ListAdapter gets updated here
Thread.Sleep(3000);
dialog.Dismiss();
});
});
I want to dismiss my dialog after 3 seconds, but what’s happening is my dialog never shows up but my list still gets updated after 3 seconds. Anything I’m doing wrong with the sleep?
What you are doing wrong there is that you are sleeping the UI thread and not the background thread you have spawned in the
TreadPool. Try with this instead: