本文整理汇总了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);
}
示例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);
}
}
}
示例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);
}
}));
}
示例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();
}
示例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();
}
示例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);
}
}));
}
示例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");
}
示例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)
{
}
}
示例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));
}
示例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;
}
示例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;
}
示例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)));
}
}
示例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;
}
示例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);
}
示例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;
});
}