次のコードを使用すると、次のエラーが発生します: Dispatcher.CurrentDispatcher.Invoke(() => actualServer.SetServerData(serverData)); デリゲート型ではないため、ラムダ式を「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));
}