/// <summary>
/// Prepares the TextDocument.
/// This method may be called by the background thread writing to the output.
/// Once the document is prepared, it can no longer be written to.
/// </summary>
/// <remarks>
/// Calling this method on the background thread ensures the TextDocument's line tokenization
/// runs in the background and does not block the GUI.
/// </remarks>
public void PrepareDocument() {
if (textDocument == null) {
textDocument = new TextDocument(b.ToString());
textDocument.SetOwnerThread(null); // release ownership
}
}