# Win32Exception Is Thrown when Multiple RadDocument Instances Are Created in Background Threads

## Environment

<table>
	<tbody>
		<tr>
			<td>Product</td>
			<td>RadRichTextBox for WPF</td>
		</tr>
	</tbody>
</table>

## Description

The **"Win32Exception (0x80004005): Not enough storage is available to process this command"** exception is thrown when multiple `RadDocument` instances are created in background threads.

The exception occurs due to a leak of `Dispatcher` instances and their related infrastructure objects. When a `DispatcherObject` type is instantiated on a thread, a `Dispatcher` instance is associated with this thread. Even after the thread finishes successfully, its `Dispatcher` is not disposed. This behavior is also reproducible with `RadDocument`, as it uses core WPF logic for some of its operations. For instance, using a `Brush` element on a thread automatically instantiates a `Dispatcher` object.

The exception is reproducible only in scenarios with heavy usage of new threads.

## Solution

If you incorporate solutions with heavy usage of new threads, use the workaround shown below, which Microsoft also recommends.

**Shutting Down the Dispatcher of a Thread**

```C#

Thread thread = new Thread(() =>
{
    // Thread logic
    System.Windows.Threading.Dispatcher.CurrentDispatcher.BeginInvokeShutdown(System.Windows.Threading.DispatcherPriority.Normal);
});
```

## See Also

* [Getting Started](https://www.telerik.com/products/wpf/documentation/controls/radrichtextbox/getting-started/getting-started)
