当前位置: 首页>>代码示例>>C#>>正文


C# Dispatcher.Invoke方法代码示例

本文整理汇总了C#中System.Windows.Threading.Dispatcher.Invoke方法的典型用法代码示例。如果您正苦于以下问题:C# Dispatcher.Invoke方法的具体用法?C# Dispatcher.Invoke怎么用?C# Dispatcher.Invoke使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Windows.Threading.Dispatcher的用法示例。


在下文中一共展示了Dispatcher.Invoke方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MainViewModel

        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);
        }
开发者ID:pupunussi,项目名称:typographify,代码行数:28,代码来源:MainViewModel.cs

示例2: StartSplashScreen

        public void StartSplashScreen()
        {
            if (_thread == null)
            {
                _thread = new Thread(StartSplashScreen);
                _thread.SetApartmentState(ApartmentState.STA);
                _thread.Start();
                return;
            }
            if (_dispatcher == null)
            {
                _dispatcher = Dispatcher.CurrentDispatcher;
                _dispatcher.Invoke(new Action(() =>
                {
                    SplashScreen = new DevExSplashScreen();
                    SplashScreen.SetProgressState(true);
                    SplashScreen.ShowDialog();
                }));

                while (!_dispatcher.HasShutdownStarted)
                {
                    _dispatcher.Invoke(new Action(() => { }), DispatcherPriority.SystemIdle);
                }
            }
        }
开发者ID:JPVenson,项目名称:Shell_Temp,代码行数:25,代码来源:SplashScreenService.cs

示例3: UpdateTagsCollection

        public void UpdateTagsCollection(string tagDisplayName, string tagValue, Dispatcher dispatcher)
        {
            bool tagFound = false;

            dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate()
            {
                foreach (TagInfo summarySignal in _summaryStatusTags)
                {
                    if (summarySignal.TagName.Equals(tagDisplayName))
                    {
                        int index = _summaryStatusTags.IndexOf(summarySignal);

                        _summaryStatusTags.RemoveAt(index);

                        summarySignal.TagName = tagDisplayName;
                        summarySignal.TagValue = tagValue;
                        _summaryStatusTags.Insert(index, summarySignal);
                        tagFound = true;
                        break;
                    }
                }

                if (!tagFound)
                {
                    TagInfo summarySignal = new TagInfo();
                    summarySignal.TagValue = tagValue;
                    summarySignal.TagName = tagDisplayName;
                    _summaryStatusTags.Add(summarySignal);
                }
            }));
        }
开发者ID:BdGL3,项目名称:CXPortal,代码行数:31,代码来源:SummaryStatus.xaml.cs

示例4: RoslynCodeAnalysisHelper

        public RoslynCodeAnalysisHelper(IWpfTextView view, ITextDocument document, IVsTaskList tasks, DTE2 dte, SVsServiceProvider serviceProvider, IVsActivityLog log)
        {
            _view = view;
            _document = document;
            _text = new Adornment();
            _tasks = tasks;
            _serviceProvider = serviceProvider;
            _log = log;
            _dispatcher = Dispatcher.CurrentDispatcher;

            _adornmentLayer = view.GetAdornmentLayer(RoslynCodeAnalysisFactory.LayerName);

            _view.ViewportHeightChanged += SetAdornmentLocation;
            _view.ViewportWidthChanged += SetAdornmentLocation;

            _text.MouseUp += (s, e) => dte.ExecuteCommand("View.ErrorList");

            _timer = new Timer(750);
            _timer.Elapsed += (s, e) =>
            {
                _timer.Stop();
                System.Threading.Tasks.Task.Run(() =>
                {
                    _dispatcher.Invoke(new Action(() => Update(false)), DispatcherPriority.ApplicationIdle, null);
                });
            };
            _timer.Start();
        }
开发者ID:karthik25,项目名称:roslyn-code-analysis-extension,代码行数:28,代码来源:RoslynCodeAnalysisHelper.cs

示例5: ErrorHighlighter

        public ErrorHighlighter(IWpfTextView view, ITextDocument document, IVsTaskList tasks, DTE2 dte)
        {
            _view = view;
            _document = document;
            _text = new Adornment();
            _tasks = tasks;
            _dispatcher = Dispatcher.CurrentDispatcher;

            _adornmentLayer = view.GetAdornmentLayer(ErrorHighlighterFactory.LayerName);

            _view.ViewportHeightChanged += SetAdornmentLocation;
            _view.ViewportWidthChanged += SetAdornmentLocation;

            _text.MouseUp += (s, e) => { dte.ExecuteCommand("View.ErrorList"); };

            _timer = new Timer(750);
            _timer.Elapsed += (s, e) =>
            {
                _timer.Stop();
                Task.Run(() =>
                {
                    _dispatcher.Invoke(new Action(() =>
                    {
                        Update(false);
                    }), DispatcherPriority.ApplicationIdle, null);
                });
            };
            _timer.Start();
        }
开发者ID:vandro,项目名称:ErrorHighlighter,代码行数:29,代码来源:ErrorHighlighter.cs

示例6: UpdateTagsCollection

        public void UpdateTagsCollection(string tagDisplayName, string tagValue, Dispatcher dispatcher)
        {
            bool tagFound = false;

            dispatcher.Invoke(DispatcherPriority.Normal, new Action(delegate()
            {
                foreach (TagInfo estop in _estopTags)
                {
                    if (estop.TagName.Equals(tagDisplayName))
                    {
                        int index = _estopTags.IndexOf(estop);

                        _estopTags.RemoveAt(index);

                        estop.TagName = tagDisplayName;
                        estop.TagValue = tagValue;
                        _estopTags.Insert(index, estop);
                        tagFound = true;
                        break;
                    }
                }

                if (!tagFound)
                {
                    TagInfo estop = new TagInfo();
                    estop.TagValue = tagValue;
                    estop.TagName = tagDisplayName;
                    _estopTags.Add(estop);
                }
            }));
        }
开发者ID:BdGL3,项目名称:CXPortal,代码行数:31,代码来源:EStopStatus.xaml.cs

示例7: GuardUiaServerInvocation

 private static void GuardUiaServerInvocation(Action invocation, Dispatcher dispatcher)
 {
     if (dispatcher == null)
         throw new ElementNotAvailableException();
     Exception remoteException = null;
     bool completed = false;
     dispatcher.Invoke(DispatcherPriority.Send, TimeSpan.FromMinutes(3.0), (Action)(() =>
     {
         try
         {
             invocation();
         }
         catch (Exception e)
         {
             remoteException = e;
         }
         catch
         {
             remoteException = null;
         }
         finally
         {
             completed = true;
         }
     }));
     if (completed)
     {
         if (remoteException != null)
             throw remoteException;
     }
     else if (dispatcher.HasShutdownStarted)
         throw new InvalidOperationException("AutomationDispatcherShutdown");
     else
         throw new TimeoutException("AutomationTimeout");
 }
开发者ID:TestStack,项目名称:uia-custom-pattern-managed,代码行数:35,代码来源:AutomationPeerAugmentationHelper.cs

示例8: ClaudiaIDE

 /// <summary>
 /// Creates a square image and attaches an event handler to the layout changed event that
 /// adds the the square in the upper right-hand corner of the TextView via the adornment layer
 /// </summary>
 /// <param name="view">The <see cref="IWpfTextView"/> upon which the adornment will be drawn</param>
 /// <param name="imageProvider">The <see cref="IImageProvider"/> which provides bitmaps to draw</param>
 /// <param name="setting">The <see cref="Setting"/> contains user image preferences</param>
 public ClaudiaIDE(IWpfTextView view, IImageProvider imageProvider, Setting setting)
 {
     try
     {
         _dispacher = Dispatcher.CurrentDispatcher;
         _imageProvider = imageProvider;
         _view = view;
         _positionHorizon = setting.PositionHorizon;
         _positionVertical = setting.PositionVertical;
         _imageOpacity = setting.Opacity;
         _fadeTime = setting.ImageFadeAnimationInterval;
         _image = new Image
         {
             Opacity = setting.Opacity,
             IsHitTestVisible = false
         };
         _adornmentLayer = view.GetAdornmentLayer("ClaudiaIDE");
         _view.ViewportHeightChanged += delegate { RepositionImage(); };
         _view.ViewportWidthChanged += delegate { RepositionImage(); };
         _view.ViewportLeftChanged += delegate { RepositionImage(); };
         _imageProvider.NewImageAvaliable += delegate { _dispacher.Invoke(ChangeImage); };
         ChangeImage();
     }
     catch (Exception)
     {
     }
 }
开发者ID:brogowski,项目名称:ClaudiaIDE,代码行数:34,代码来源:ClaudiaIDE.cs

示例9: StatisticsViewModel

        public StatisticsViewModel(Statistics statistics)
        {
            _statistics = statistics;
            StatisticsList = new ObservableCollection<string>();

            _dispatcher = Dispatcher.CurrentDispatcher;
            _timer = new Timer(s => _dispatcher.Invoke((Action)(Update)), null, TimeSpan.Zero, TimeSpan.FromMilliseconds(250));
        }
开发者ID:chadjriddle,项目名称:GenesisEngine,代码行数:8,代码来源:StatisticsViewModel.cs

示例10: ConvertBitmapToImageSourceOnDispatcher

        public static BitmapSource ConvertBitmapToImageSourceOnDispatcher(Bitmap bitmap, Dispatcher dispatcher)
        {
            BitmapSource source = null;

            Action<object> dispatcherDelegate = x => { source = ConvertBitmapToImageSource(x as Bitmap); };
            dispatcher.Invoke(dispatcherDelegate, bitmap);

            return source;
        }
开发者ID:kmees,项目名称:NMagnify,代码行数:9,代码来源:BitmapUtility.cs

示例11: TelemetryData

        private TelemetryData(int udpPort, Dispatcher dispatcher)
        {
            _dispatcher = dispatcher;
            _dispatcher.Invoke(() => Status = "Starting");

            _udpReceiver = new UdpReceiver(udpPort);
            Debug.WriteLine("Starting telemetry receiver on port " + udpPort);
            _lastReceiveTime = DateTime.Now;
        }
开发者ID:246overclocked,项目名称:Notifications,代码行数:9,代码来源:TelemetryData.cs

示例12: DeckList

        public DeckList(string path, Dispatcher disp, DeckList parent = null, bool isRoot = false)
        {
            Parent = parent;
            Path = path;
            Name = new DirectoryInfo(path).Name;

            if (isRoot) IsRootFolder = true;

            DeckLists = new ObservableCollection<DeckList>();
            Decks = new ObservableCollection<MetaDeck>();

            foreach (var f in Directory.GetDirectories(path).Select(x => new DirectoryInfo(x)))
            {
                if (isRoot)
                {
                    if (DataNew
                        .DbContext.Get()
                        .Games
                        .Any(x => x.Name.Equals(f.Name, StringComparison.InvariantCultureIgnoreCase)))
                    {
                        var dl = new DeckList(f.FullName, disp, this);
                        dl.IsGameFolder = true;
                        disp.Invoke(new Action(() => DeckLists.Add(dl)));
                    }
                }
                else
                {
                    var dl = new DeckList(f.FullName, disp, this);
                    disp.Invoke(new Action(() => DeckLists.Add(dl)));
                }
            }

            foreach (var f in Directory.GetFiles(Path, "*.o8d"))
            {
                var deck = new MetaDeck(f);
                disp.Invoke(new Action(() => Decks.Add(deck)));
            }
            foreach (var d in DeckLists.SelectMany(x => x.Decks))
            {
                MetaDeck d1 = d;
                disp.Invoke(new Action(() => Decks.Add(d1)));
            }
        }
开发者ID:boykathemad,项目名称:OCTGN,代码行数:43,代码来源:DeckManager.xaml.cs

示例13: CreateProgressDialog

		public static IProgressDialog CreateProgressDialog(
			IDialogHost dialogHost,
			DialogMode dialogMode,
			Dispatcher dispatcher)
		{
			IProgressDialog dialog = null;
			dispatcher.Invoke(
				new Action(() => dialog = new WaitProgressDialog(
					dialogHost, dialogMode, false, dispatcher)),
				DispatcherPriority.DataBind);
			return dialog;
		}
开发者ID:tsbrzesny,项目名称:rma-alzheimer,代码行数:12,代码来源:WaitProgressDialog.cs

示例14: OnUiThreadSync

        public static void OnUiThreadSync(Action action, Dispatcher disp = null,
			DispatcherPriority prio = DispatcherPriority.Background)
        {
            if (disp == null)
            {
                if (Application.Current != null)
                    disp = Application.Current.Dispatcher;
            }

            if (disp != null)
                disp.Invoke(action, prio);
        }
开发者ID:rajkosto,项目名称:DayZeroLauncher,代码行数:12,代码来源:Execute.cs

示例15: FilteredHttpsProtocol

        public FilteredHttpsProtocol(Dispatcher dispatcher, IUrlFilter urlFilter)
        {
            ArgumentUtility.CheckNotNull ("dispatcher", dispatcher);
              ArgumentUtility.CheckNotNull ("urlFilter", urlFilter);

              _urlFilter = urlFilter;
              _dispatcher = dispatcher;
              _dispatcher.Invoke (
              () =>
              {
            var originalHandler = new HttpsProtocol();
            _wrapped = (IInternetProtocol) originalHandler;
              });
        }
开发者ID:rubicon-oss,项目名称:DesktopGap,代码行数:14,代码来源:FilteredHttpsProtocol.cs


注:本文中的System.Windows.Threading.Dispatcher.Invoke方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。