使用以下代码时出现以下错误: Dispatcher.CurrentDispatcher.Invoke(() => actualServer.SetServerData(serverData)); 无法将 lambda 表达式转换为类型“System.Delegate”,因为它不是委托类型
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
var source = new List<ServerProperty>
{
new ServerProperty("connectionstring1", "server1"),
new ServerProperty("connectionstring2", "server2"),
new ServerProperty("connectionstring3", "server3"),
new ServerProperty("connectionstring4", "server4"),
};
DataContext = source;
_timer = new Timer((t) =>
{
foreach (var serverProperty in source)
{
ServerProperty server = serverProperty;
ThreadPool.QueueUserWorkItem((o) =>
{
var serverData = ServerDataCalculator.GetServerData(server.ConnectionString);
var actualServer = (ServerProperty)o;
Dispatcher.CurrentDispatcher.Invoke(() => actualServer.SetServerData(serverData));
}, server);
}
}, null, TimeSpan.FromSeconds(2), TimeSpan.FromSeconds(2));
}