CallDispatcherAsync() public static method

Calls the UI thread dispatcher and executes the given callback on it.
public static CallDispatcherAsync ( DispatchedHandler callback ) : Task
callback DispatchedHandler The callback that should be executed in the UI thread.
return Task
        protected virtual async void OnPropertyChanged(PropertyChangedEventArgs args)
        {
            // Prevent interrupting the dispatcher thread in case there is nothing to do:
            if (PropertyChanged is null)
            {
                return;
            }

            if (invokeInUiThread)
            {
                // Make sure we call the PropertyChanged event from the UI thread:
                await SharedUtils.CallDispatcherAsync(() =>
                {
                    try
                    {
                        // Keep the null check since this can happen later:
                        PropertyChanged?.Invoke(this, args);
                    }
                    catch (Exception e)
                    {
                        throw e;
                    }
                });
            }
            else
            {
                PropertyChanged.Invoke(this, args);
            }
        }
 protected virtual async void OnPropertyChanged([CallerMemberName] string name = "")
 {
     if (invokeInUiThread)
     {
         // Make sure we call the PropertyChanged event from the UI thread:
         await SharedUtils.CallDispatcherAsync(() => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name)));
     }
     else
     {
         PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
     }
 }
Beispiel #3
0
        protected virtual async void OnPropertyChanged([CallerMemberName] string name = "")
        {
            // Prevent interrupting the dispatcher thread in case there is nothing to do:
            if (PropertyChanged is null)
            {
                return;
            }

            if (invokeInUiThread)
            {
                // Make sure we call the PropertyChanged event from the UI thread:
                try
                {
                    await SharedUtils.CallDispatcherAsync(() =>
                    {
                        try
                        {
                            // Keep the null check since this can happen later:
                            PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
                        }
                        catch (Exception e)
                        {
                            throw e;
                        }
                    });
                }
                catch (Exception e)
                {
                    Logger.Error("Failed to invoke UI thread.", e);
                }
            }
            else
            {
                PropertyChanged.Invoke(this, new PropertyChangedEventArgs(name));
            }
        }