.NET Framework Class Library
Thread.GetDomain Method
Returns the current domain in which the current thread is running.
Assembly: mscorlib (in mscorlib.dll)
Syntax
Visual Basic
Public Shared Function GetDomain As AppDomain
C#
public static AppDomain GetDomain()
Visual C++
public: static AppDomain^ GetDomain()
F#
static member GetDomain : unit -> AppDomain
Return Value
Type: System.AppDomainAn 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.
Visual Basic
Imports System 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
C#
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()); } }
Visual C++
using namespace System; using namespace System::Threading; ref class Test { private: Test(){} public: static void ThreadMethod() { Console::WriteLine( "Thread {0} started in {1} with AppDomainID = {2}.", AppDomain::GetCurrentThreadId().ToString(), Thread::GetDomain()->FriendlyName, Thread::GetDomainID().ToString() ); } }; int main() { Thread^ newThread = gcnew Thread( gcnew ThreadStart( &Test::ThreadMethod ) ); newThread->Start(); }
Version Information
.NET Framework
Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0.NET Framework Client Profile
Supported in: 4, 3.5 SP1Platforms
Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2
The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
See Also