我的调度员有问题。我的程序用于观看特定文件夹。
我的代码在这里:
if (watcherChangeTypes == System.IO.WatcherChangeTypes.Renamed)
Dispatcher.BeginInvoke(new Action(() => { AddlistLine(string.Format("{0}->{1} to -> {2} at {3} ", watcherChangeTypes.ToString(), oldName, name, DateTime.Now)); }));
Run Code Online (Sandbox Code Playgroud)
但我错误地认为当前上下文中不存在名称调度程序。我已经声明使用system.threading;
但它不起作用。
通常我会检查我是否可以访问ObservableCollection,如果没有,我会调用一个Dispatcher. 这里(上Stackoverflow)还有其他一些解决方案,但我不知道什么是最好和最干净的方法。我认为我的解决方案已经过时,不应再使用。
在我的例子中是ItemsCollection绑定到UI. 该_UpdateTheCollectionFromAnotherThread()会被调用(从另一个thread或将开启另一个thread)并保存数据暂时到items。之后,我会检查访问权限并dispatcher在需要时调用 a 。
这是我必须走的路还是有一些更好更清洁的解决方案?
public class FooClass
{
// ##############################################################################################################################
// Properties
// ##############################################################################################################################
/// <summary>
/// This Items are bound to my UI.
/// </summary>
public ObservableCollection<string> ItemsCollection { get; } = new ObservableCollection<string>();
// ##############################################################################################################################
// Singleton pattern
// ##############################################################################################################################
/// <summary>
/// The instance of <see cref="FooClass"/>.
/// </summary>
internal static FooClass Instance …Run Code Online (Sandbox Code Playgroud) 有人知道 Shopware 6 中的每个事件是否都存在列表,类似于 Magento 2 中的controller_action_postdispatch?我需要一个在每个控制器操作上触发的 Shopware 6 事件,以便我可以将客户重定向到登录表单(如果未登录)。
我System.Windows.Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Input, new Action(() => ...用于wpf图形刷新.
它非常适用于我的其他功能,但是在我的SQL删除功能中,它会被触发/执行.
我试了一下,System.Windows.Forms.Application.DoEvents();但它做了什么.
Set_Loading_Changed()
{
System.Windows.Application.Current.Dispatcher.BeginInvoke(DispatcherPriority.Input, new Action(() =>
{
if (BLoading)
{
TextBox_Warten.Margin = new Thickness(ComboBox_Such_Optionen.Margin.Left, ComboBox_Such_Optionen.Margin.Top, Btn_Suchen.Margin.Right, Btn_Suchen.Margin.Bottom);
DataGrid_Anzeige.IsEnabled = false;
foreach (System.Windows.Controls.TextBox TextBox_Temp in Grid_Mw.Children.OfType<System.Windows.Controls.TextBox>().Where(x => !x.Name.Contains("TextBox_Warten")))
{
TextBox_Temp.IsEnabled = false;
}
foreach (System.Windows.Controls.Button Btn_Temp in Grid_Mw.Children.OfType<System.Windows.Controls.Button>())
{
Btn_Temp.IsEnabled = false;
}
foreach (System.Windows.Controls.ComboBox ComboBox_Temp in Grid_Mw.Children.OfType<System.Windows.Controls.ComboBox>())
{
ComboBox_Temp.IsEnabled = false;
}
Mouse.OverrideCursor = System.Windows.Input.Cursors.Wait;
}
else
{
DataGrid_Anzeige.IsEnabled = true;
DataGrid_Anzeige.Opacity = 100;
TextBox_Warten.Margin = new Thickness(-TextBox_Warten.Width - …Run Code Online (Sandbox Code Playgroud)