ICSharpCode.AvalonEdit.Document.TextDocument.SetOwnerThread C# (CSharp) Method

SetOwnerThread() public method

Transfers ownership of the document to another thread. This method can be used to load a file into a TextDocument on a background thread and then transfer ownership to the UI thread for displaying the document.

The owner can be set to null, which means that no thread can access the document. But, if the document has no owner thread, any thread may take ownership by calling SetOwnerThread.

public SetOwnerThread ( Thread newOwner ) : void
newOwner Thread
return void
        public void SetOwnerThread(Thread newOwner)
        {
            // We need to lock here to ensure that in the null owner case,
            // only one thread succeeds in taking ownership.
            lock (lockObject) {
                if (owner != null) {
                    VerifyAccess();
                }
                owner = newOwner;
            }
        }

Usage Example

Esempio n. 1
0
		/// <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
			}
		}