Essentials icon indicating copy to clipboard operation
Essentials copied to clipboard

[QUESTION] MainThread.BeginInvokeOnMainThread

Open angelru opened this issue 4 years ago • 4 comments

I have to update the ui (ObservableCollection) through an event synchronous (SignalR) it may be that at that moment the application is not with that view visible because the user is in another view. I went to test with MainThread.BeginInvokeOnMainThread and it didn't work, but with Device.BeginInvokeOnMainThread it got updated. Are there big differences?

angelru avatar Mar 02 '21 07:03 angelru

Would need to compare code. What platform?

jamesmontemagno avatar Apr 13 '21 19:04 jamesmontemagno

A colleague at my work, also faced with this. The difference is in the if else construct. Unfortunately he didn't have the sample code saved

public static bool IsMainThread =>
    PlatformIsMainThread;

public static void BeginInvokeOnMainThread(Action action)
{
    if (IsMainThread)
    {
        action();
    }
    else
    {
        PlatformBeginInvokeOnMainThread(action);
    }
}

dimonovdd avatar Apr 15 '21 18:04 dimonovdd

It happened to me on android, to see if I take the time and do the example.

angelru avatar Apr 16 '21 06:04 angelru

@dimonovdd and what was the solution?

angelru avatar Apr 18 '21 07:04 angelru