System.Windows.Threading.Dispatcher.Invoke C# (CSharp) Method

Invoke() private method

private Invoke ( Delegate d ) : void
d Delegate
return void
		internal void Invoke (Delegate d, params object[] args)
		{
			if (CheckAccess ()) {
				try {
					InvokeDelegate (d, args);
				} catch (Exception ex) {
					Application.OnUnhandledException (this, ex);
				}
			} else {
				ManualResetEvent wait = new ManualResetEvent (false);
				BeginInvoke (delegate {
					try {
						InvokeDelegate (d, args);
					} catch (Exception ex) {
						Application.OnUnhandledException (this, ex);
					} finally {
						wait.Set ();
					}
				});
				wait.WaitOne ();
			}
		}

Usage Example

        public MainViewModel(ITypographService serivce, ISettings settings)
        {
            _service = serivce;
            Settings = settings;
            _dispatcher = Dispatcher.CurrentDispatcher;

            ShowSettingsFlyout = new RelayCommand(() =>
            {
                _dispatcher.Invoke(() => IsSettingsFlyoutOpen = true);
            });

            Typographify = new RelayCommand(() =>
            {
                _dispatcher.Invoke(() => IsWorking = true);

                _service.Typographify(Text, (result, error) =>
                {
                    if (error != null)
                        _HandleException(error);

                    if (result != null)
                        _dispatcher.Invoke(() => Text = result);

                    _dispatcher.Invoke(() => IsWorking = false);
                });
            }
            , () => !string.IsNullOrWhiteSpace(Text) && !IsWorking);
        }
All Usage Examples Of System.Windows.Threading.Dispatcher::Invoke