Performance
A WPF window freezes whenever its dispatcher is busy, and loading, converting and merging documents can keep it busy for seconds or minutes. Developers who build editors, report generators or batch tools with TX Text Control .NET for WPF find here how its classes fit the threading model of WPF, how to move long work to other threads and processes, how to handle large documents and memory, and which of Text Control's measurements back each recommendation.
The Editor and the Engine Without a Window
Two classes hold documents, and they belong to different threads:
WPF TextControl | ServerTextControl | |
|---|---|---|
| Used for | The document the user sees and edits | Documents your code creates, converts, merges or prints |
| Thread | The UI thread of its window, reached through its Dispatcher | Any thread, one instance per thread |
| Undo buffer and screen rendering | Yes | No |
| Disposal | Not disposable; it lives as long as its window | Disposed by your code, in a using block |
Load, Save and the merge methods of MailMerge are synchronous and occupy the thread that calls them. Work that takes longer than a moment therefore runs in a ServerTextControl on a thread of the thread pool, and only the result goes back to the editor. TX Text Control is thread safe, but its threads can wait for each other, which is why Text Control recommends separate processes for very large batches.
Find the Right Page
| If you want to | Read |
|---|---|
| Understand which objects belong to the UI thread and get results back to the editor | Dispatcher and UI Thread Access |
| Convert or process many files on other threads, with progress and a cancel button | Background Operations |
| Build and process documents with hundreds of pages | Large Documents |
| Dispose instances, find leaks and stay below the handle limits of Windows | Memory Usage and Resource Disposal |
| Choose the format documents are kept in and load only what a task needs | Document Loading and Conversion |
| Know what a merge costs, merge in the background and in separate processes | Mail Merge Performance |
| See every measure at a glance and measure your own documents | Performance Best Practices |
Recommended Order
- Dispatcher and UI Thread Access: the rules every other page builds on.
- Background Operations: the pattern for any work that takes longer than a moment.
- Performance Best Practices: the remaining measures, each linked to its page.
The measurements quoted in this section are Text Control's own, and most of them were taken with TX Text Control .NET Server. Each is given with the conditions it was measured under; your documents and computers decide the actual numbers.