这些都不起作用:
_uiDispatcher.Invoke(() => { });
_uiDispatcher.Invoke(delegate() { });
Run Code Online (Sandbox Code Playgroud)
我想要做的就是在我的主UI线程上调用内联方法.所以我在主线程上调用了这个:
_uiDispatcher = Dispatcher.CurrentDispatcher;
Run Code Online (Sandbox Code Playgroud)
现在我想从另一个线程在该线程上执行一些代码.我该怎么做?我使用了错误的语法吗?
请注意,这不是 WPF应用程序; 我引用了WindowsBase所以我可以访问Dispatcher该类.
我想在WPF应用程序的主线程上执行此代码并获取错误我无法弄清楚出了什么问题:
private void AddLog(string logItem)
{
this.Dispatcher.BeginInvoke(
delegate()
{
this.Log.Add(new KeyValuePair<string, string>(DateTime.Now.ToLongTimeString(), logItem));
});
}
Run Code Online (Sandbox Code Playgroud) 我有这样的问题:有一些方法
private List<int> GetStatusList()
{
return (List<int>)GetValue(getSpecifiedDebtStatusesProperty);
}
Run Code Online (Sandbox Code Playgroud)
在主线程中调用它 - 我使用
`delegate List<int> ReturnStatusHandler();` ...
this.Dispatcher.Invoke(new ReturnStatusHandler(GetStatusList));
Run Code Online (Sandbox Code Playgroud)
我怎么能这样做,使用lambda表达式而不是自定义委托和方法?
在以下行"this.dgvReport.Invoke(delegate")中收到错误
"无法将匿名方法转换为'System.Delegate'类型,因为它不是委托类型"
public void FillProductGrid()
{
ProductSP productSP = new ProductSP();
DataTable dtbl = new DataTable();
string productname = "";
dtbl = productSP.StockReport(productname, this.cbxPrint.Checked);
this.dgvReport.Invoke(delegate
{
this.dgvReport.DataSource = dtbl;
});
}
Run Code Online (Sandbox Code Playgroud)