【发布时间】:2011-12-29 11:53:43
【问题描述】:
我尝试了以下操作:
var task = new Task(() =>
{
for (int i=0; i<10; i++) {
//Create new Grid HERE
// Add Table with some dynamic data here..
// print the above Grid here.
}
});
task.ContinueWith((previousTask) =>
{
label.Content = printerStatus(); // will return "Out of Paper", "printing", "Paper jam", etc.
},
TaskScheduler.FromCurrentSynchronizationContext());
label.Content = "Sending to printer";
返回如下错误:调用线程必须是STA,因为很多UI组件都需要这个..
尝试创建新的 UI 对象 Grid 时发生错误。
我该如何解决这个问题?让我知道是否还有其他方法!
【问题讨论】:
标签: c# .net wpf multithreading