XPS 문서에 쓰려고 할 때 왜 이상한 예외가 발생합니까?UI 스레드와 다른 스레드에서 XPS로 인쇄하면 가능합니까?
XpsPackagingException:
Package already has a root DocumentSequence or FixedDocument.
내 목표는 XPS 파일로 WPF 비주얼을 인쇄하는 것입니다,하지만 시각적 트리가 너무 크기 때문에, 인쇄의 과정은 매우 느릴 수있다, 그래서 내가에 XPS 파일을 인쇄 할 수있는 방법을 찾으려면 배경 스레드 때문에 내 사용자가 고정 된 응용 프로그램 때문에 화를 내지 않을 것입니다.
Dispatcher otherThreadDispatcher;
public MainWindow()
{
InitializeComponent();
Thread thread = new Thread(() =>
{
otherThreadDispatcher = Dispatcher.CurrentDispatcher;
printIt.Click += new RoutedEventHandler(printIt_Click);
System.Windows.Threading.Dispatcher.Run();
});
thread.SetApartmentState(ApartmentState.STA);
thread.Start();
}
void printIt_Click(object sender, RoutedEventArgs e)
{
otherThreadDispatcher.Invoke(new Action(() =>
{
using (XpsDocument myDoc = new XpsDocument("foo.xps", FileAccess.ReadWrite))
{
XpsDocumentWriter writer = XpsDocument.CreateXpsDocumentWriter(myDoc);
var collator = writer.CreateVisualsCollator();
collator.BeginBatchWrite();
collator.Write(someImageToPrint);
collator.EndBatchWrite();
}
}));
}
응용 프로그램이나 응용 프로그램의 스크린 샷을 인쇄 하시겠습니까? 이 경우 백그라운드에서 인쇄를하면 인쇄하는 동안 사용자 인터페이스가 변경 될 수 있습니다. 그게 문제 야. 나는 당신이 사용자에게 throbber를 선물 할 수 있는지 궁금해. 그래서 그들은 앱의 간단한 "동결"을 경험하지 않을 것이다. 이 경우에 당신의 throbbe ritself는 XPS에 들어갈 수 있습니다. –
someimagetoprint는 어떤 유형입니까? 빈 xps doc에 대해서도 오류가 발생합니까? –