Note

Access to this page requires authorization. You can try signing in or .

Access to this page requires authorization. You can try .

Thread.GetDomain Method

Definition

Namespace:
System.Threading
Assemblies:
netstandard.dll, System.Threading.Thread.dll
Assembly:
System.Threading.Thread.dll
Assembly:
mscorlib.dll
Assembly:
netstandard.dll
Source:
Thread.cs
Source:
Thread.cs
Source:
Thread.cs
Source:
Thread.cs
Source:
Thread.cs

Important

Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.

Returns the current domain in which the current thread is running.

public:
 static AppDomain ^ GetDomain();
public static AppDomain GetDomain();
static member GetDomain : unit -> AppDomain
Public Shared Function GetDomain () As AppDomain

Returns

An AppDomain representing the current application domain of the running thread.

Examples

The following code example shows how to retrieve the name and ID of the AppDomain in which the thread is running.

using System;
using System.Threading;

class Test
{
 static void Main()
 {
 Thread newThread = new Thread(new ThreadStart(ThreadMethod));
 newThread.Start();
 }

 static void ThreadMethod()
 {
 Console.WriteLine(
 "Thread {0} started in {1} with AppDomainID = {2}.",
 AppDomain.GetCurrentThreadId().ToString(), 
 Thread.GetDomain().FriendlyName, 
 Thread.GetDomainID().ToString());
 }
}
open System
open System.Threading

let threadMethod () =
 printfn $"Thread {AppDomain.GetCurrentThreadId()} started in {Thread.GetDomain().FriendlyName} with AppDomainID = {Thread.GetDomainID()}."

let newThread = Thread threadMethod
newThread.Start()
Imports System.Threading

Public Class Test

 <MTAThread> _
 Shared Sub Main()
 Dim newThread As New Thread(AddressOf ThreadMethod)
 newThread.Start()
 End Sub

 Shared Sub ThreadMethod()
 Console.WriteLine( _
 "Thread {0} started in {1} with AppDomainID = {2}.", _
 AppDomain.GetCurrentThreadId().ToString(), _
 Thread.GetDomain().FriendlyName, _
 Thread.GetDomainID().ToString())
 End Sub

End Class

Applies to


Feedback

Was this page helpful?