我想从运行在后台线程中的代码加载Xaml。 我知道我必须与调度员同步。但是,它失败(抛出异常)。 为什么?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是在另一个线程中创建和销毁的)。 – 2011-04-07 18:35:14