Ejemplo n.º 1
0
        public bool ReceiveWeakEvent(Type managerType, object sender, EventArgs e)
        {
            var notify = e as NotifyCollectionChangedEventArgs;

            if (notify == null)
            {
                return(false);
            }

            if (_compatible)
            {
                Refresh();
                return(true);
            }

            try {
                ActionExtension.InvokeInMainThread(() => {
                    OnCollectionChanged(sender, notify);
                });
            } catch (ArgumentOutOfRangeException ex) {
                _compatible = true;

                Logging.Debug("That weird ListCollectionView crash, switching to the compatible mode…");
                Logging.Debug(notify.Action);
                Logging.Debug($"Old: {notify.OldStartingIndex}; new: {notify.NewStartingIndex}");
                Logging.Debug($"Old: {string.Join(", ", notify.OldItems.OfType<object>())}; new: {string.Join(", ", notify.NewItems.OfType<object>())}");
                Logging.Debug(ex);

                Refresh();
            } catch (Exception ex) {
                Logging.Warning(ex);
                Refresh();
            }

            return(true);
        }
Ejemplo n.º 2
0
 public static Task ContinueWithInMainThread(this Task task, Action <Task> callback, TaskContinuationOptions options = TaskContinuationOptions.None)
 {
     return(task.ContinueWith(r => ActionExtension.InvokeInMainThreadAsync(() => callback(r)), options));
 }