【发布时间】:2011-04-07 18:31:01
【问题描述】:
我想从后台线程中运行的代码加载 Xaml。 我知道我必须与调度员同步。但是,它失败了(抛出异常)。 为什么?
这里是代码
public MainWindow()
{
InitializeComponent();
Thread thread = new Thread(new ThreadStart(delegate
{
Dispatcher.Invoke(new Action(delegate
{
Content = XamlReader.Parse(
"<Button xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation'
Content='Hello World'/>");
}));
}));
thread.Start();
}
【问题讨论】:
-
“失败”?发生什么了 ? (可能什么都没有,因为 o 是在另一个线程中创建和销毁的)。
标签: wpf multithreading xaml