# Dispatcher and Thread Access

> Keep a WPF application with TX Text Control responsive: ServerTextControl for work without a user interface, parallel merges and unhandled exceptions.

- **Product:** TX Text Control .NET for WPF
- **Section:** Documentation
- **Kind:** Topic
- **Path:** TX Text Control .NET for WPF > Troubleshooting > Dispatcher and Thread Access
- **800 words**
- **Web URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/troubleshooting/dispatcher/
- **LLMs URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/troubleshooting/dispatcher/llms.txt
- **LLMs-Full URL:** https://docs.textcontrol.com/tx-text-control-dotnet-wpf/troubleshooting/dispatcher/llms-full.txt

---

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](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/performance/dispatcher/llms-full.txt) 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](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/servertextcontrol/llms-full.txt), 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.

1. Create a `ServerTextControl` in a `using` block for each task, and call [Create](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/servertextcontrol/create-method/llms-full.txt) before you use it.
2. Load, change and save the documents with it, and load only the result into the `TextControl` of the window.

The blog article [Replace TextControl: Using ServerTextControl for Non-UI Background Tasks](https://www.textcontrol.com/blog/2014/05/26/replace-textcontrol-using-servertextcontrol-for-non-ui-background-tasks/) describes the approach; its licensing steps are those of the .NET Framework. [Background Operations](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/performance/background-operations/llms-full.txt) 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](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/performance/background-operations/#how-far-threads-take-you) explains. For large batches, such as mail merges of many documents, Text Control recommends separate processes.

1. 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](https://www.textcontrol.com/blog/2019/08/16/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.

1. Handle `Application.Current.DispatcherUnhandledException` in your application.
2. Show or log `e.Exception.Message`, and set `e.Handled` to `true` for exceptions your application can continue after, such as a [LicenseLevelException](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/reference/txtextcontrol/licenselevelexception/llms-full.txt).

[Handle Exceptions Nobody Caught](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/document-processing/exceptions/#handle-exceptions-nobody-caught) shows the handler, and [Licensing](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/troubleshooting/licensing/#a-feature-isn-t-available-in-your-edition) explains the `LicenseLevelException`.

### Related Pages

- [Dispatcher and UI Thread Access](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/performance/dispatcher/llms-full.txt): the threading model of the control.
- [Background Operations](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/performance/background-operations/llms-full.txt): work that runs in the background.
- [Control Initialization](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/troubleshooting/initialization/llms-full.txt): code that runs before the control is ready.

---

## Nearby

- **Previous:** [Data Binding and Commands](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/troubleshooting/data-binding/llms-full.txt)
- **Next:** [Licensing](https://docs.textcontrol.com/tx-text-control-dotnet-wpf/troubleshooting/licensing/llms-full.txt)
