Here are the examples of the csharp api System.Windows.Threading.Dispatcher.BeginInvoke(System.Delegate, params object[]) taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.
520 Examples
19
View Source File : Machine.cs
License : MIT License
Project Creator : 3RD-Dimension
License : MIT License
Project Creator : 3RD-Dimension
private void RaiseEvent(Action<string> action, string param)
{
if (action == null)
return;
Application.Current.Dispatcher.BeginInvoke(action, param);
}
19
View Source File : Machine.cs
License : MIT License
Project Creator : 3RD-Dimension
License : MIT License
Project Creator : 3RD-Dimension
private void RaiseEvent(Action action)
{
if (action == null)
return;
Application.Current.Dispatcher.BeginInvoke(action);
}
19
View Source File : Execute.cs
License : MIT License
Project Creator : 944095635
License : MIT License
Project Creator : 944095635
public static void InitializeWithDispatcher()
{
var dispatcher = Dispatcher.CurrentDispatcher;
executor = (action, async) =>
{
//确认是当前的线程
if (dispatcher.CheckAccess())
{
action();
}
else
{
//异步执行
if (async)
{
dispatcher.BeginInvoke(action);
}
else
{
dispatcher.Invoke(action);
}
}
};
}
19
View Source File : DigitalAnalyzerExampleViewModel.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
private async Task AddChannels(int digitalChannelsCount, int replacedogChannelsCount)
{
List<byte[]> digitalChannels = new List<byte[]>();
List<float[]> replacedogChannels = new List<float[]>();
// Force GC to free memory
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true);
try
{
// Allocate memory first
await Task.Run(() =>
{
for (var i = 0; i < digitalChannelsCount; i++)
{
var newArray = new byte[SelectedPointCount];
digitalChannels.Add(newArray);
}
for (var i = 0; i < replacedogChannelsCount; i++)
{
var newArray = new float[SelectedPointCount];
replacedogChannels.Add(newArray);
}
});
// Generate random data and fill channels
await GenerateData(digitalChannels, replacedogChannels);
}
catch (OutOfMemoryException)
{
await Application.Current.Dispatcher.BeginInvoke(new Action(() => ChannelViewModels.Clear()));
MessageBox.Show(string.Format($"There is not enough RAM memory to allocate {SelectedChannelCount} channels with {SelectedPointCount} points each. Please select less channels or less points and try again."));
}
finally
{
OnPropertyChanged(nameof(IsEmpty));
OnPropertyChanged(nameof(ChannelViewModels));
OnPropertyChanged(nameof(SelectedPointCount));
OnPropertyChanged(nameof(TotalPoints));
OnPropertyChanged(nameof(XRange));
IsLoading = false;
}
}
19
View Source File : EndlessItemsControl.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
private void AddMoreItems()
{
var isBusy = (bool)GetValue(IsBusyProperty);
if (!isBusy)
{
SetValue(IsBusyProperty, true);
SetValue(IsBusyProperty, false);
SetValue(IsBusyProperty, true);
var delay = (TimeSpan)GetValue(PreLoadingDelayProperty);
Task.Factory.StartNew(() =>
{
Thread.Sleep(delay);
var items = _allItems.Take(10).ToList();
items.ForEach(item =>
{
Dispatcher.BeginInvoke(new Action(() => Currenreplacedems.Add(item)));
_allItems.Remove(item);
});
}).ContinueWith(_ =>
{
Dispatcher.BeginInvoke(new Action(() => SetValue(IsBusyProperty, false)));
});
}
}
19
View Source File : VerticallyStackedAxes.xaml.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
private void OnLoaded(object sender, RoutedEventArgs e)
{
Task.Factory.StartNew(() =>
{
// Creates 8 dataseries with data on a background thread
var dataSeries = new List<IDataSeries>();
for (int i = 0; i < 8; i++)
{
var ds = new XyDataSeries<double, double>();
dataSeries.Add(ds);
var someData = DataManager.Instance.GetAcousticChannel(i);
ds.Append(someData.XData, someData.YData);
}
// Creates 8 renderable series on the UI thread
Dispatcher.BeginInvoke(new Action(() => CreateRenderableSeries(dataSeries)));
});
}
19
View Source File : ScatterChartPerformanceTest.xaml.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
private void OnLoaded(object sender, RoutedEventArgs routedEventArgs)
{
// Create our data in another thread to stop the UI from being stalled.
// It's not appending to SciChart data series that is the problem, its Calling Rand.Next() two million times which is pretty slow :)
TimedMethod.Invoke(() =>
{
var dataSeries = new XyDataSeries<double, double>() {AcceptsUnsortedData = true};
var rand = new Random();
// Allow 1M points in WPF/DirectX. In Silverlight or software rendering, 100k points is enough to stress the renderer
int count = FeaturesHelper.Instance.SupportsHardwareAcceleration ? (int) 1E6 : (int) 1E5;
// Append some data
for (int i = 0; i < count; i++)
{
dataSeries.Append(rand.NextDouble(), rand.NextDouble());
}
// Bind to scichart
Action bindData = () => { BindData(dataSeries); };
Dispatcher.BeginInvoke(bindData);
}).After(200).OnThread(TimedMethodThread.Background).Go();
}
19
View Source File : AudioDeviceSource.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
private void RefreshDevices()
{
if (!_dispatcher.CheckAccess())
{
_dispatcher.BeginInvoke((Action)RefreshDevices);
return;
}
DefaultDevice = GetDefaultDevice();
var deviceMap = Devices.ToDictionary(d => d.ID, d => d);
var presentDevices = new HashSet<string>();
foreach (var d in _enumerator.EnumerateAudioEndPoints(DataFlow.Capture, DeviceState.Active))
{
presentDevices.Add(d.ID);
if(deviceMap.TryGetValue(d.ID, out var device))
{
device.Update(d);
}
else
{
Devices.Add(new AudioDeviceInfo(d));
}
d.Dispose();
}
for (int i = Devices.Count - 1; i >=0; i--)
{
if (!presentDevices.Contains(Devices[i].ID))
{
Devices.RemoveAt(i);
}
}
DevicesChanged?.Invoke(this, EventArgs.Empty);
}
19
View Source File : DispatcherObservableCollection.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
public bool Remove(T item)
{
if (_dispatcher.CheckAccess())
return DoRemove(item);
else
{
bool? result = null;
_dispatcher.BeginInvoke(new Func<T, bool>(t =>
{
result = DoRemove(t);
return result.Value;
}), item);
return result != null && result != false;
}
}
19
View Source File : DispatcherObservableCollection.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
private void OnCollectionChanged(NotifyCollectionChangedEventArgs e)
{
var handler = CollectionChanged;
if (handler == null) return;
if (_dispatcher.CheckAccess())
handler(this, e);
else
_dispatcher.BeginInvoke((Action)(() => handler(this, e)));
}
19
View Source File : DigitalAnalyzerExampleViewModel.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
private async Task AddChannels(int digitalChannelsCount)
{
var digitalChannels = new List<byte[]>();
// Force GC to free memory
GCSettings.LargeObjectHeapCompactionMode = GCLargeObjectHeapCompactionMode.CompactOnce;
GC.Collect(GC.MaxGeneration, GCCollectionMode.Forced, true);
try
{
// Allocate memory first
await Task.Run(() =>
{
for (var i = 0; i < digitalChannelsCount; i++)
{
var newArray = new byte[SelectedPointCount];
digitalChannels.Add(newArray);
}
});
// Generate random data and fill channels
await GenerateData(digitalChannels);
}
catch (OutOfMemoryException)
{
await Application.Current.Dispatcher.BeginInvoke(new Action(() => ChannelViewModels.Clear()));
MessageBox.Show(string.Format($"There is not enough RAM memory to allocate {SelectedChannelCount} channels with {SelectedPointCount} points each. Please select less channels or less points and try again."));
}
finally
{
OnPropertyChanged(nameof(IsEmpty));
OnPropertyChanged(nameof(ChannelViewModels));
OnPropertyChanged(nameof(SelectedPointCount));
OnPropertyChanged(nameof(TotalPoints));
OnPropertyChanged(nameof(XRange));
IsLoading = false;
}
}
19
View Source File : TimerRunner.cs
License : MIT License
Project Creator : ABTSoftware
License : MIT License
Project Creator : ABTSoftware
public virtual void Run()
{
timer = new Timer();
timer.Interval = 10; // 100Hz
//timer.Interval = 1; // 100Hz
ElapsedEventHandler tickHandler = null;
tickHandler = (s, e) =>
{
_testCallback();
lock (this)
{
if (_stopped) return;
if (_stopWatch.ElapsedMilliseconds > _duration.TotalMilliseconds)
{
_stopWatch.Stop();
_stopped = true;
timer.Elapsed -= tickHandler;
timer.Stop();
double fps = _frameCount/_stopWatch.Elapsed.TotalSeconds;
Application.Current.Dispatcher.BeginInvoke(new Action(() => _completedCallback(fps)));
}
}
};
timer.Elapsed += tickHandler;
_stopWatch = Stopwatch.StartNew();
timer.Start();
}
19
View Source File : MainWindow.xaml.cs
License : GNU General Public License v2.0
Project Creator : adrifcastr
License : GNU General Public License v2.0
Project Creator : adrifcastr
public override void Write(char value)
{
base.Write(value);
_output.Dispatcher.BeginInvoke(new Action(() =>
{
_output.AppendText(value.ToString());
}));
}
19
View Source File : EditorModel.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu
License : Mozilla Public License 2.0
Project Creator : agebullhu
private void Context_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
{
if (e.PropertyName == nameof(Context.SelectConfig))
{
ExtendEditorPanel.Dispatcher.BeginInvoke(CheckWindowAction);
}
}
19
View Source File : DispatcherSynchronousContext.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu
License : Mozilla Public License 2.0
Project Creator : agebullhu
public void BeginInvokeInUiThread(Action action)
{
if (Dispatcher.CheckAccess())
{
action();
}
else
{
Dispatcher.BeginInvoke(action);
}
}
19
View Source File : DispatcherSynchronousContext.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu
License : Mozilla Public License 2.0
Project Creator : agebullhu
public void BeginInvokeInUiThread<T>(Action<T> action, T args)
{
if (Dispatcher.CheckAccess())
{
action(args);
}
else
{
Dispatcher.BeginInvoke(action, args);
}
}
19
View Source File : DispatcherSynchronousContext.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu
License : Mozilla Public License 2.0
Project Creator : agebullhu
public void BeginInvokeInUiThread<T1, T2>(Action<T1, T2> action, T1 args1, T2 args2)
{
if (Dispatcher.CheckAccess())
{
action(args1, args2);
}
else
{
Dispatcher.BeginInvoke(action, args1, args2);
}
}
19
View Source File : DispatcherSynchronousContext.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu
License : Mozilla Public License 2.0
Project Creator : agebullhu
public void BeginInvokeInUiThread<T1, T2, T3>(Action<T1, T2, T3> action, T1 args1, T2 args2, T3 arg3)
{
if (Dispatcher.CheckAccess())
{
action(args1, args2, arg3);
}
else
{
Dispatcher.BeginInvoke(action, args1, args2, arg3);
}
}
19
View Source File : StepTackProxy.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu
License : Mozilla Public License 2.0
Project Creator : agebullhu
private void OnEnd(Task<TResult> task)
{
// ReSharper disable PossibleNullReferenceException
lock (this)
{
var item = task.AsyncState as TackStepItem;
if (item.StepKey != StepKey)
return;
switch (task.Status)
{
case TaskStatus.Faulted:
LogRecorder.Exception(task.Exception);
Status = CommandStatus.Faulted;
break;
default:
Status = CommandStatus.Succeed;
break;
}
Dispatcher.BeginInvoke(new Action<TResult>(Exist), task.Result);
}
// ReSharper restore PossibleNullReferenceException
}
19
View Source File : DispatcherSynchronousContext.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu
License : Mozilla Public License 2.0
Project Creator : agebullhu
public void BeginInvokeInUiThread<T1, T2, T3, T4>(Action<T1, T2, T3, T4> action, T1 args1, T2 args2, T3 arg3, T4 arg4)
{
if (Dispatcher.CheckAccess())
{
action(args1, args2, arg3, arg4);
}
else
{
Dispatcher.BeginInvoke(action, args1, args2, arg3, arg4);
}
}
19
View Source File : StepTackProxy.cs
License : Mozilla Public License 2.0
Project Creator : agebullhu
License : Mozilla Public License 2.0
Project Creator : agebullhu
private void OnEnd(Task task)
{
lock (this)
{
// ReSharper disable PossibleNullReferenceException
var item = task.AsyncState as TackStepItem;
if (item.StepKey != StepKey)
return;
// ReSharper restore PossibleNullReferenceException
_task = null;
switch (task.Status)
{
case TaskStatus.Faulted:
LogRecorder.Exception(task.Exception);
Status = CommandStatus.Faulted;
break;
default:
Status = CommandStatus.Succeed;
break;
}
Dispatcher.BeginInvoke(new Action(Exist));
}
}
19
View Source File : SettingsControl.xaml.cs
License : MIT License
Project Creator : AkiniKites
License : MIT License
Project Creator : AkiniKites
private void UpdateCacheStatus()
{
Async.Run(() =>
{
var cSize = Paths.GetDirectorySize(IoC.Config.CachePath);
var iSize = Paths.GetDirectorySize(IoC.Config.ImagesPath);
Dispatcher.BeginInvoke(new Action(() =>
{
lblCacheSize.Text = $"{((cSize + iSize) / 1024):n0} KB";
btnClearCache.IsEnabled = cSize > 0;
btnClearImages.IsEnabled = iSize > 0;
}));
}).ConfigureAwait(false);
}
19
View Source File : MainWindow.xaml.cs
License : MIT License
Project Creator : AkiniKites
License : MIT License
Project Creator : AkiniKites
private void AddMigrations()
{
var width = this.Width;
var height = this.Height;
//add reset window migration
AppCompatibility.AddMigration(new Version(1, 7, 5), () =>
{
Dispatcher.BeginInvoke(new Action(() =>
{
this.Width = width;
this.Height = height;
}));
});
}
19
View Source File : MainWindow.xaml.cs
License : MIT License
Project Creator : AkiniKites
License : MIT License
Project Creator : AkiniKites
public void SetAppStatus(string text)
{
text ??= "";
text = SingleLineConverter.Convert(text);
Dispatcher.BeginInvoke(new Action(() =>
{
tssAppStatus.Text = text;
}));
}
19
View Source File : MainWindow.xaml.cs
License : MIT License
Project Creator : AkiniKites
License : MIT License
Project Creator : AkiniKites
public void SetStatus(string text, bool error)
{
text ??= "";
text = SingleLineConverter.Convert(text);
Dispatcher.BeginInvoke(new Action(() =>
{
tssStatus.Text = text;
tssStatus.Foreground = error ?
new SolidColorBrush(UIColors.ErrorColor) :
SystemColors.WindowTextBrush;
}));
}
19
View Source File : MainWindow.xaml.cs
License : MIT License
Project Creator : AkiniKites
License : MIT License
Project Creator : AkiniKites
public void SetProgress(int current, int max, bool unknown, bool visible)
{
Dispatcher.BeginInvoke(new Action(() =>
{
tssAppStatus.Visibility = !visible ? Visibility.Visible : Visibility.Hidden;
tpbStatus.Visibility = visible ? Visibility.Visible : Visibility.Hidden;
if (visible)
{
tpbStatus.IsIndeterminate = unknown;
if (!unknown)
{
tpbStatus.Maximum = max;
tpbStatus.Value = current;
}
}
}));
}
19
View Source File : NodesTree.cs
License : MIT License
Project Creator : alaabenfatma
License : MIT License
Project Creator : alaabenfatma
private void BuildNodes()
{
Task.Factory.StartNew(() =>
{
Dispatcher.BeginInvoke(new Action(() =>
{
foreach (var node in _pluginsManager.LoadedNodes)
for (var index = 0; index < Roots.Count; index++)
if (node.Category == Roots[index].NodeName)
Roots[index].Nodes.Add(new NodeItem("", node.Clone()));
}));
});
}
19
View Source File : VariablesList.cs
License : MIT License
Project Creator : alaabenfatma
License : MIT License
Project Creator : alaabenfatma
public void UpdateType(string nameOfType)
{
var varListSelectedItem = (VariableItem) _varList.SelectedItem;
RTypes rtype;
switch (nameOfType)
{
case "Generic":
rtype = RTypes.Generic;
break;
case "Character":
rtype = RTypes.Character;
break;
case "Logical":
rtype = RTypes.Logical;
break;
case "Numeric":
rtype = RTypes.Numeric;
break;
case "DataFrame":
rtype = RTypes.DataFrame;
break;
default:
rtype = RTypes.ArrayOrFactorOrListOrMatrix;
break;
}
if (varListSelectedItem != null)
{
varListSelectedItem.Type = nameOfType;
foreach (var id in varListSelectedItem.DsOfNodes)
foreach (var node in Host.Nodes)
if (node.Id == id)
if (node.InExecPorts.Count == 0)
{
node.OutputPorts[0].Data.Type = rtype;
NodesManager.ChangeColorOfVariableNode(node.OutputPorts[0], nameOfType);
}
else if (node.InputPorts != null)
{
NodesManager.ChangeColorOfVariableNode(node.InputPorts[0], nameOfType);
node.InputPorts[0].Data.Type = rtype;
}
Application.Current.Dispatcher.BeginInvoke(new Action(UpdateWires));
}
}
19
View Source File : VirtualControl.cs
License : MIT License
Project Creator : alaabenfatma
License : MIT License
Project Creator : alaabenfatma
private void OnMouseUp(object sender, MouseButtonEventArgs mouseButtonEventArgs)
{
if (MouseMode == MouseMode.SelectionRectangle && Children.Contains(_selectionZone))
{
Children.Remove(_selectionZone);
SelectedNodes.Clear();
for (var index = 0; index < Nodes.Count; index++)
{
var node = Nodes[index];
if (node.IsSelected) SelectedNodes.Add(node);
}
MouseMode = MouseMode.Nothing;
}
if (MouseMode == MouseMode.ResizingComment)
{
TempComment.Cursor = Cursors.Arrow;
TempComment = null;
}
HideLinkingPossiblity();
Cursor = Cursors.Arrow;
if (WireMode == WireMode.FirstPortSelected && (TemExecPort != null || TemObjectPort != null))
{
NodesTree.Show();
MouseMode = MouseMode.Nothing;
WireMode = WireMode.Nothing;
}
else
{
Children.Remove(TempConn);
MouseMode = MouseMode.Nothing;
WireMode = WireMode.Nothing;
}
_mouseEffect.Show(this, Colors.DarkGray);
Task.Factory.StartNew(() =>
{
Thread.Sleep(300);
Application.Current.Dispatcher.BeginInvoke(new Action(() => { _mouseEffect.Remove(this); }));
});
}
19
View Source File : SingularNotificationManager.cs
License : GNU General Public License v3.0
Project Creator : alexdillon
License : GNU General Public License v3.0
Project Creator : alexdillon
public void Show(object content, string areaName = "", TimeSpan? expirationTime = null, Action onClick = null, Action onClose = null, bool CloseOnClick = true)
{
if (!this.Dispatcher.CheckAccess())
{
this.Dispatcher.BeginInvoke(new Action(() => this.Show(content, areaName, expirationTime, onClick, onClose)));
return;
}
if (window != null && notificationArea != null)
{
if (!window.IsVisible)
{
window.Visibility = Visibility.Visible;
window.Show();
window.WindowState = WindowState.Normal;
}
notificationArea.Show(
content,
expirationTime ?? TimeSpan.FromSeconds(5),
onClick,
onClose,
CloseOnClick);
}
}
19
View Source File : ScrollIntoViewForListbox.cs
License : GNU General Public License v3.0
Project Creator : alexdillon
License : GNU General Public License v3.0
Project Creator : alexdillon
private void replacedociatedObject_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (sender is ListBox)
{
ListBox listBox = sender as ListBox;
if (listBox.SelectedItem != null)
{
listBox.Dispatcher.BeginInvoke(
(Action)(() =>
{
var scrollToTopAction = ListBoxExtensions.GetScrollToTop(listBox);
var scrollToBottomAction = ListBoxExtensions.GetScrollToBottom(listBox);
ListBoxExtensions.SetScrollToTop(listBox, null);
ListBoxExtensions.SetScrollToBottom(listBox, null);
listBox.UpdateLayout();
if (listBox.SelectedItem != null)
{
listBox.ScrollIntoView(listBox.SelectedItem);
}
ListBoxExtensions.SetScrollToTop(listBox, scrollToTopAction);
ListBoxExtensions.SetScrollToBottom(listBox, scrollToBottomAction);
}));
}
}
}
19
View Source File : Relay.cs
License : MIT License
Project Creator : AliFlux
License : MIT License
Project Creator : AliFlux
public void notify(string json)
{
dispatcher.BeginInvoke((Action)(() =>
{
callback(json);
}));
}
19
View Source File : SmartDispatcher.cs
License : GNU General Public License v3.0
Project Creator : AndreiFedarets
License : GNU General Public License v3.0
Project Creator : AndreiFedarets
public void BeginInvoke(Action action)
{
_dispatcher.BeginInvoke(action);
}
19
View Source File : DelayedNotification.cs
License : GNU General Public License v3.0
Project Creator : AndreiFedarets
License : GNU General Public License v3.0
Project Creator : AndreiFedarets
private void OnTimerElapsed(object sender, System.Timers.ElapsedEventArgs e)
{
lock (_lock)
{
T value = _currentValue;
Action callback = () => _callback(value);
if (_dispatcher == null)
{
callback.BeginInvoke(null, null);
}
else
{
_dispatcher.BeginInvoke(callback);
}
}
}
19
View Source File : MainViewModel.cs
License : MIT License
Project Creator : AntonyCorbett
License : MIT License
Project Creator : AntonyCorbett
private void MergeFiles()
{
var destPath = _fileOpenSaveService.GetSaveFilePath(GetSaveDialogreplacedle());
if (string.IsNullOrWhiteSpace(destPath))
{
return;
}
IsBusy = true;
Task.Run(() =>
{
PrepareForMerge();
try
{
var schemaFilePath = GetSuitableFilePathForSchema();
if (schemaFilePath != null)
{
var mergedFile = _backupFileService.Merge(Files.Select(x => x.BackupFile).ToArray());
_backupFileService.WriteNewDatabase(mergedFile, destPath, schemaFilePath);
_snackbarService.Enqueue("Merged successfully");
}
}
catch (Exception ex)
{
_snackbarService.Enqueue("Could not merge. See log file for more information");
Log.Logger.Error(ex, "Could not merge");
}
finally
{
// we need to ensure the files are back to normal after
// applying any merge parameters.
ReloadFiles();
}
}).ContinueWith(_ => Application.Current.Dispatcher.BeginInvoke(new Action(() => IsBusy = false)));
}
19
View Source File : CountdownOutputDisplayService.cs
License : MIT License
Project Creator : AntonyCorbett
License : MIT License
Project Creator : AntonyCorbett
public void Stop()
{
IsCountdownDone = true;
IsCountingDown = false;
WeakReferenceMessenger.Default.Send(new CountdownWindowStatusChangedMessage { Showing = false });
if (_optionsService.CanDisplayTimerWindow)
{
_timerOutputDisplayService.ShowWindow();
}
Task.Delay(1000).ContinueWith(t =>
{
Application.Current.Dispatcher.BeginInvoke(new Action(Close));
});
}
19
View Source File : SnackbarService.cs
License : MIT License
Project Creator : AntonyCorbett
License : MIT License
Project Creator : AntonyCorbett
public void Enqueue(object content)
{
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
if (Application.Current.MainWindow?.WindowState != WindowState.Minimized)
{
TheSnackbarMessageQueue.Enqueue(content);
}
}));
}
19
View Source File : SnackbarService.cs
License : MIT License
Project Creator : AntonyCorbett
License : MIT License
Project Creator : AntonyCorbett
public void EnqueueWithOk(object content)
{
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
if (Application.Current.MainWindow?.WindowState != WindowState.Minimized)
{
TheSnackbarMessageQueue.Enqueue(content, Properties.Resources.OK, () => { });
}
}));
}
19
View Source File : SnackbarService.cs
License : MIT License
Project Creator : AntonyCorbett
License : MIT License
Project Creator : AntonyCorbett
public void EnqueueWithOk(object content)
{
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
if (Application.Current.MainWindow?.WindowState != WindowState.Minimized)
{
TheSnackbarMessageQueue.Enqueue(content, "OK", () => { });
}
}));
}
19
View Source File : CountdownWindow.xaml.cs
License : MIT License
Project Creator : AntonyCorbett
License : MIT License
Project Creator : AntonyCorbett
private void OnCountDownTimeUp(object sender, EventArgs e)
{
CountDown.Stop();
Task.Delay(1000).ContinueWith(t =>
{
Application.Current.Dispatcher.BeginInvoke(new Action(OnTimeUpEvent));
});
}
19
View Source File : MainWindow.xaml.cs
License : MIT License
Project Creator : AntonyCorbett
License : MIT License
Project Creator : AntonyCorbett
private void BringMainWindowToFront()
{
Task.Delay(100).ContinueWith((t) =>
{
Application.Current.Dispatcher.BeginInvoke(new Action(() =>
{
Activate();
}));
});
}
19
View Source File : Dispatcher.cs
License : GNU General Public License v3.0
Project Creator : AnyStatus
License : GNU General Public License v3.0
Project Creator : AnyStatus
public void InvokeAsync(Action action)
{
if (Application.Current is null)
{
Debug.WriteLine("The dispatcher cannot invoke actions because the application is null.");
}
else if (Application.Current.Dispatcher is null)
{
Debug.WriteLine("The dispatcher cannot invoke actions because the application dispatcher is null.");
}
else if (Application.Current.CheckAccess())
{
action();
}
else
{
Application.Current.Dispatcher.BeginInvoke(action);
}
}
19
View Source File : SpotifyRemoteSettingsControl.xaml.cs
License : MIT License
Project Creator : arjankuijpers
License : MIT License
Project Creator : arjankuijpers
private void UpdateUIColors()
{
var defaultBackground = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowBackgroundColorKey);
var defaultForeground = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowTextColorKey);
System.Drawing.Color c = VSColorTheme.GetThemedColor(EnvironmentColors.ToolWindowBackgroundColorKey);
SolidColorBrush backgroundCol = new SolidColorBrush(ThemeHelper.ToMediaColor(defaultBackground));
switch (ThemeHelper.GetTheme())
{
case ThemeHelper.eVSTheme.kDark:
foregroundColor = Color.FromRgb(255, 255, 255);
subOptionsColor = Color.FromRgb(130, 203, 247);
explainOptColor = Color.FromRgb(255, 255, 255);
Windowreplacedle.Foreground = new SolidColorBrush(Color.FromRgb(186, 255, 171));
Windowreplacedle.Background = new SolidColorBrush(ThemeHelper.ToMediaColor(defaultBackground));
Background = backgroundCol;
//listView.Background = backgroundCol;
break;
case ThemeHelper.eVSTheme.kBlue:
foregroundColor = Color.FromRgb(0, 0, 0);
subOptionsColor = Color.FromRgb(100, 106, 106);
explainOptColor = Color.FromRgb(0, 0, 0);
Windowreplacedle.Foreground = new SolidColorBrush(Color.FromRgb(83, 114, 76));
Windowreplacedle.Background = new SolidColorBrush(ThemeHelper.ToMediaColor(defaultBackground));
Background = backgroundCol;
//.Background = backgroundCol;
break;
case ThemeHelper.eVSTheme.kLight:
foregroundColor = Color.FromRgb(0, 0, 0);
subOptionsColor = Color.FromRgb(100, 106, 106);
explainOptColor = Color.FromRgb(0, 0, 0);
Windowreplacedle.Foreground = new SolidColorBrush(Color.FromRgb(83, 114, 76));
Windowreplacedle.Background = backgroundCol;
Background = backgroundCol;
//listView.Background = backgroundCol;
break;
case ThemeHelper.eVSTheme.kUnknown:
//break;
default:
byte a = defaultForeground.A;
byte r = defaultForeground.R;
byte g = defaultForeground.G;
byte b = defaultForeground.B;
foregroundColor = Color.FromArgb(a, r, g, b);
subOptionsColor = Color.FromArgb(a, r, g, b);
explainOptColor = Color.FromArgb(a, r, g, b);
Windowreplacedle.Foreground = new SolidColorBrush(foregroundColor);
Windowreplacedle.Background = new SolidColorBrush(ThemeHelper.ToMediaColor(defaultBackground));
Dispatcher.BeginInvoke(new System.Action(() => MessageBox.Show("Spotify extension couldn't detect color scheme. \nWould you be so kind to file a bug report?")));
break;
}
//SetListViewColors(foregroundColor);
UpdateSettingsreplacedles(foregroundColor);
UpdateSettingsSubOptions(subOptionsColor);
UpdateExplainationSettings(explainOptColor);
}
19
View Source File : AcrylicMenuItem.cs
License : MIT License
Project Creator : awaescher
License : MIT License
Project Creator : awaescher
protected override void OnSubmenuOpened(RoutedEventArgs e)
{
base.OnSubmenuOpened(e);
Dispatcher.BeginInvoke((Action)BlurSubMenu);
}
19
View Source File : TextBoxHelper.cs
License : Apache License 2.0
Project Creator : beckzhu
License : Apache License 2.0
Project Creator : beckzhu
private static void ControlGotFocus<TDependencyObject>(TDependencyObject sender, Action<TDependencyObject> action) where TDependencyObject : DependencyObject
{
if (sender != null)
{
if (GetSelectAllOnFocus(sender))
{
sender.Dispatcher.BeginInvoke(action, sender);
}
}
}
19
View Source File : Layout.cs
License : Apache License 2.0
Project Creator : beckzhu
License : Apache License 2.0
Project Creator : beckzhu
private void UnfloatExecuted(object sender, ExecutedRoutedEventArgs executedRoutedEventArgs)
{
var dragablzItem = executedRoutedEventArgs.Parameter as DragablzItem;
if (dragablzItem == null) return;
var exemplarTabControl = this.VisualTreeDepthFirstTraversal().OfType<TabablzControl>()
.FirstOrDefault(t => t.InterTabController != null && t.InterTabController.Parreplacedion == Parreplacedion);
if (exemplarTabControl == null) return;
//TODO preplaceding the exemplar tab in here isnt ideal, as strictly speaking there isnt one.
var newTabHost = exemplarTabControl.InterTabController.InterTabClient.GetNewHost(exemplarTabControl.InterTabController.InterTabClient,
exemplarTabControl.InterTabController.Parreplacedion, exemplarTabControl);
if (newTabHost == null || newTabHost.TabablzControl == null || newTabHost.Container == null)
throw new ApplicationException("New tab host was not correctly provided");
var floatingItemSnapShots = dragablzItem.VisualTreeDepthFirstTraversal()
.OfType<Layout>()
.SelectMany(l => l.FloatingDragablzItems().Select(FloatingItemSnapShot.Take))
.ToList();
var content = dragablzItem.Content ?? dragablzItem;
//remove from source
CollectionTeaser collectionTeaser;
if (CollectionTeaser.TryCreate(FloatingItemsSource, out collectionTeaser))
collectionTeaser.Remove(content);
else
FloatingItems.Remove(content);
var myWindow = Window.GetWindow(this);
if (myWindow == null) throw new ApplicationException("Unable to find owning window.");
newTabHost.Container.Width = myWindow.RestoreBounds.Width;
newTabHost.Container.Height = myWindow.RestoreBounds.Height;
newTabHost.Container.Left = myWindow.Left + 20;
newTabHost.Container.Top = myWindow.Top + 20;
Dispatcher.BeginInvoke(new Action(() =>
{
newTabHost.TabablzControl.AddToSource(content);
newTabHost.TabablzControl.SelectedItem = content;
newTabHost.Container.Show();
newTabHost.Container.Activate();
Dispatcher.BeginInvoke(
new Action(() => RestoreFloatingItemSnapShots(newTabHost.TabablzControl, floatingItemSnapShots)));
}), DispatcherPriority.DataBind);
}
19
View Source File : DragablzItem.cs
License : Apache License 2.0
Project Creator : beckzhu
License : Apache License 2.0
Project Creator : beckzhu
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
var thumbAndSubscription = SelectAndSubscribeToThumb();
_templateSubscriptions.Disposable = thumbAndSubscription.Item2;
if (_seizeDragWithTemplate && thumbAndSubscription.Item1 != null)
{
_isTemplateThumbWithMouseAfterSeize = true;
Mouse.AddLostMouseCaptureHandler(this, LostMouseAfterSeizeHandler);
if (_dragSeizedContinuation != null)
_dragSeizedContinuation(this);
_dragSeizedContinuation = null;
Dispatcher.BeginInvoke(new Action(() => thumbAndSubscription.Item1.RaiseEvent(new MouseButtonEventArgs(InputManager.Current.PrimaryMouseDevice,
0,
MouseButton.Left) {RoutedEvent = MouseLeftButtonDownEvent})));
}
_seizeDragWithTemplate = false;
}
19
View Source File : DragablzItemsControl.cs
License : Apache License 2.0
Project Creator : beckzhu
License : Apache License 2.0
Project Creator : beckzhu
private void ItemDragCompleted(object sender, DragablzDragCompletedEventArgs eventArgs)
{
var dragablzItems = DragablzItems()
.Select(i =>
{
i.IsDragging = false;
i.IsSiblingDragging = false;
return i;
})
.ToList();
if (ItemsOrganiser != null)
{
var bounds = new Size(ActualWidth, ActualHeight);
ItemsOrganiser.OrganiseOnDragCompleted(this, bounds,
dragablzItems.Except(eventArgs.DragablzItem),
eventArgs.DragablzItem);
}
eventArgs.Handled = true;
//wowsers
Dispatcher.BeginInvoke(new Action(InvalidateMeasure));
Dispatcher.BeginInvoke(new Action(InvalidateMeasure), DispatcherPriority.Loaded);
}
19
View Source File : MainWindow.xaml.cs
License : Apache License 2.0
Project Creator : beetlex-io
License : Apache License 2.0
Project Creator : beetlex-io
private void SetTime(DateTime time)
{
this.Dispatcher.BeginInvoke(new Action<DateTime>(t =>
{
this.txtTime.Content = t.ToString();
}), time);
}
19
View Source File : WpfLogEventSink.cs
License : GNU General Public License v3.0
Project Creator : Bililive
License : GNU General Public License v3.0
Project Creator : Bililive
public void Emit(LogEvent logEvent)
{
var msg = logEvent.RenderMessage();
if (logEvent.Exception != null)
msg += " " + logEvent.Exception.Message;
var m = new LogModel
{
Timestamp = logEvent.Timestamp,
Level = logEvent.Level,
Message = msg,
};
if (logEvent.Properties.TryGetValue(LoggingContext.RoomId, out var propertyValue)
&& propertyValue is ScalarValue scalarValue
&& scalarValue.Value is int roomid)
{
m.RoomId = roomid.ToString();
}
var current = Application.Current;
if (current is null)
lock (_lock)
this.AddLogToCollection(m);
else
_ = current.Dispatcher.BeginInvoke((Action<LogModel>)this.AddLogToCollection, m);
}
See More Examples