1
我有一個方法(CreateDocument)在最後觸發事件。事件參數包含一個FixedDocument。在我的主窗口代碼中,我試圖像設置的DocumentViewer的文檔:「因爲不同的線程擁有它調用線程不能訪問該對象」從另一個線程設置DocumentViewer.Document?
void lpage_DocCreated(object sender, LabelDocumentEventArgs e)
{
this.Dispatcher.BeginInvoke(DispatcherPriority.Normal,
new DispatcherOperationCallback(delegate
{
FixedDocument fd = e.doc;
documentViewer1.Document = fd;
documentViewer1.FitToWidth();
return null;
}), null);
}
我收到在線documentViewer1.Document = fd;
我能更新另一個事件處理的進度條,同樣的方法火災而它的工作:
Int32 progress = Int32.Parse(sender.ToString());
progBar.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Normal,
new DispatcherOperationCallback(delegate
{
progBar.Value = progress;
return null;
}), null);
我想不通爲什麼我不能設置文檔時,我當我設置進度欄值時,m本質上是做同樣的事情。