Dispatcher and Thread Access
The WPF TextControl belongs to the user interface of your window, and long-running work on the documents, such as converting or merging many files, keeps the window from responding while it runs. Text Control documents no error that is specific to the Dispatcher of WPF; what its sources describe is how to move document work away from the editor and how the samples catch exceptions that nobody else catches. Dispatcher and UI Thread Access explains the threading model of the control.
The Window Freezes While Documents Are Processed
The window doesn't respond while your application converts, merges or creates documents with the TextControl of the window.
The TextControl is a control of the user interface. Work that doesn't need a user interface belongs in a ServerTextControl, which is part of TX Text Control .NET for WPF as well: it is meant for processes in the background where no user interface is required, and it supports several threads.
- Create a
ServerTextControlin ausingblock for each task, and call Create before you use it. - Load, change and save the documents with it, and load only the result into the
TextControlof the window.
The blog article Replace TextControl: Using ServerTextControl for Non-UI Background Tasks describes the approach; its licensing steps are those of the .NET Framework. Background Operations shows how to run the work.
Parallel Tasks Don't Get Faster
Several threads process documents with TX Text Control at the same time, but the work isn't faster than on one thread.
TX Text Control protects its internal state with critical sections, so the threads that use it can wait for each other, as How Far Threads Take You explains. For large batches, such as mail merges of many documents, Text Control recommends separate processes.
- Run large batches in separate processes that each use their own instance of TX Text Control.
The blog article True Parallel Processing of Documents using MailMerge shows this with a sample for Windows Forms and states that the concept applies to WPF applications as well.
An Exception Ends the Application
An exception thrown while the user works with the editor, for example a LicenseLevelException for a feature of another edition, ends the application.
The exception isn't caught where it is thrown. The TX Words samples catch such exceptions in the DispatcherUnhandledException event of the application, show the message and mark the exception as handled.
- Handle
Application.Current.DispatcherUnhandledExceptionin your application. - Show or log
e.Exception.Message, and sete.Handledtotruefor exceptions your application can continue after, such as a LicenseLevelException.
Handle Exceptions Nobody Caught shows the handler, and Licensing explains the LicenseLevelException.