コード例 #1
0
            public override void OnInvoke(MethodInterceptionArgs args)
            {
                IDispatcherObject threadAffined = args.Instance as IDispatcherObject;
                IDispatcher       dispatcher    = threadAffined.Dispatcher;

                if (dispatcher == null)
                {
                    throw new InvalidOperationException("Cannot dispatch method: synchronization context is null");
                }


                if (this.isAsync)
                {
                    dispatcher.BeginInvoke(new WorkItem(args, true));
                }
                else if (dispatcher.CheckAccess())
                {
                    args.Proceed();
                }
                else
                {
                    WorkItemWithExceptionInterceptor workItem = new WorkItemWithExceptionInterceptor(args);
                    dispatcher.Invoke(workItem);

                    if (workItem.HasError)
                    {
                        throw new AggregateException("Exception has been thrown by the target of an invocation", workItem.Exception);
                    }
                }
            }
コード例 #2
0
 /// <summary>
 /// Changes the size of the render.
 /// </summary>
 /// <param name="width">The width.</param>
 /// <param name="height">The height.</param>
 public override void ChangeRenderSize(int width, int height)
 {
     if (!dispatcher.CheckAccess())
     {
         dispatcher.Invoke(DispatcherPriority.Background, () => ChangeRenderSize(width, height));
     }
     else
     {
         if (0 >= width || 0 >= height)
         {
             return;
         }
         renderWidth  = width;
         renderHeight = height;
         var bitmap   = new WriteableBitmap(renderWidth, renderHeight, 96d, 96d, PixelFormats.Bgra32, null);
         var newSetup = new RenderSetup
         {
             Bitmap  = bitmap,
             Context = new RenderContext(bitmap.BackBuffer, renderWidth, renderHeight, bitmap.BackBufferStride),
             Dirty   = new Int32Rect(0, 0, width, height)
         };
         OnSourceCreated(bitmap);
         setup = newSetup;
     }
 }
コード例 #3
0
        //    private NotifyCollectionChangedEventArgs eLast;
        // this is connected to the DispatherTimer
        private void TimerCallback(object state)
        {
            lock (_lock)
            {
//        trottlteNotification = false;
                // Fire the event on the UI thread
                if (Dispatcher.CheckAccess())
                {
#if TEST
                    logger.Debug("direct notification");
#endif
                    base.OnCollectionChanged(new System.Collections.Specialized.NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction.Reset));
                }
                else
                {
#if TEST
                    logger.Debug("dispatcher notification");
#endif
                    // base.
                    Dispatcher.BeginInvoke(() => base.OnCollectionChanged(new System.Collections.Specialized.NotifyCollectionChangedEventArgs(System.Collections.Specialized.NotifyCollectionChangedAction.Reset)));
                }
                if (this.onCountChange != null)
                {
                    this.onCountChange();
                }
            }
        }
コード例 #4
0
 private void SafeNotify(Action method, bool post)
 {
     try
     {
         // Fire the event on the UI thread
         if (post)
         {
             if (Dispatcher.CheckAccess())
             {
                 method();
             }
             else
             {
                 Dispatcher.BeginInvoke(method);
             }
         }
         // Fire event on a ThreadPool thread
         else
         {
             ThreadPool.QueueUserWorkItem(o => method(), null);
         }
     }
     catch (Exception ex)
     {
         // If there's an exception write it to the Output window
         Debug.WriteLine(ex.ToString());
     }
 }
コード例 #5
0
        public void ShowError(Exception exception, IErrorContainer errorContainer)
        {
            if (exception == null)
            {
                return;
            }

            ErrorContainer errorGrid = (ErrorContainer)errorContainer;

            if (!_dispatcher.CheckAccess())
            {
                _dispatcher.BeginInvoke(() => ShowError(exception, errorGrid));
                return;
            }

            ErrorNotification errorNotification = new ErrorNotification();

            errorGrid.RowDefinitions.Add(new RowDefinition {
                Height = GridLength.Auto
            });
            errorNotification.SetValue(Grid.RowProperty, errorGrid.RowDefinitions.Count - 1);
            errorGrid.Children.Add(errorNotification);
            errorGrid.UpdateLayout(); // Force OnApplyTemplate for ErrorNotification

            errorNotification.Show(exception);
        }
コード例 #6
0
ファイル: FileCollection.cs プロジェクト: judwhite/CD-Tag
        /// <summary>Raises the <see cref="ObservableCollection&lt;FileView&gt;.CollectionChanged"/> event.</summary>
        /// <param name="e">The <see cref="System.Collections.Specialized.NotifyCollectionChangedEventArgs"/> instance containing the event data.</param>
        protected override void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
        {
            if (!_dispatcher.CheckAccess())
            {
                _dispatcher.BeginInvoke(() => OnCollectionChanged(e));
                return;
            }

            base.OnCollectionChanged(e);
        }
コード例 #7
0
 public static void EasyBeginInvoke(this IDispatcher dispatcher, Delegate method, object arg)
 {
     if (dispatcher.CheckAccess())
     {
         method.Method.Invoke(method.Target, new [] { arg });
     }
     else
     {
         dispatcher.BeginInvoke(method, arg);
     }
 }
コード例 #8
0
 /// <summary>
 /// Execute an action on the UI thread.
 /// </summary>
 /// <param name="action"></param>
 public static void Execute(Action action)
 {
     if (_dispatcher.CheckAccess())
     {
         action();
     }
     else
     {
         _dispatcher.BeginInvoke(action);
     }
 }
コード例 #9
0
ファイル: App.xaml.cs プロジェクト: ekahlenberger/HandMeAFile
        private void CreateSettingsWindow(object sender, EventArgs e)
        {
            if (!m_dispatcher.CheckAccess())
            {
                Dispatcher.Invoke(() => CreateSettingsWindow(sender, e));
                return;
            }

            IProvideService <ICreateCommands <ProgressInfo> > commandCreatorProvider = new ServiceProvider <ICreateCommands <ProgressInfo> >();
            SettingsWindowViewModel viewModel = new SettingsWindowViewModel(m_packsRepository, commandCreatorProvider, m_dispatcher);

            commandCreatorProvider.Set(new CommandCreator <ProgressInfo>(new SimpleDefaultUiInteractionProvider <ProgressInfo>(viewModel.ExceptionHandler, viewModel.Progress)));

            m_settingsWindow = new SettingsWindow(viewModel);
            m_settingsWindow.Show();
        }
コード例 #10
0
 // https://msdn.microsoft.com/en-us/library/ms973852.aspx
 public static void InternalNotifyPropertyChanged(string propertyName,
                                                  object sender, PropertyChangedEventHandler propertyChanged, IDispatcher dispatcher)
 {
     if (propertyChanged != null)
     {
         if (dispatcher == null)
         {
             return;
         }
         PropertyChangedEventArgs arg = new PropertyChangedEventArgs(propertyName);
         // Fire the event on the UI thread
         if (dispatcher.CheckAccess())
         {
             propertyChanged(sender, arg);
         }
         else
         {
             dispatcher.BeginInvoke(() => propertyChanged(sender, arg));
         }
     }
 }
コード例 #11
0
ファイル: ViewModelBase.cs プロジェクト: judwhite/NsqMon
 /// <summary>
 /// Determines whether the calling thread is the thread associated with this
 /// <see cref="System.Windows.Threading.Dispatcher" />.
 /// </summary>
 /// <returns>
 /// <c>true</c> if the calling thread is the thread associated with this
 /// <see cref="System.Windows.Threading.Dispatcher" />; otherwise, <c>false</c>.
 /// </returns>
 protected bool CheckAccess()
 {
     return(_dispatcher.CheckAccess());
 }
コード例 #12
0
 protected virtual bool CheckAccess()
 {
     return(dispatcher.CheckAccess());
 }