This documentation is archived and is not being maintained.

Thread.GetDomain Method

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

[Visual Basic]
Public Shared Function GetDomain() As AppDomain
[C#]
public static AppDomain GetDomain();
[C++]
public: static AppDomain* GetDomain();
[JScript]
public static function GetDomain() : AppDomain;

Return Value

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

Remarks

The get and set accessors work on the hard thread, not the logical thread. Therefore, they are package-protected and should not be available for general consumption.

Example

[Visual Basic, C#, C++] 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

    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());
    }
}

[C++] 
#using <mscorlib.dll>
using namespace System;
using namespace System::Threading;

__gc class Test
{
    Test() {}
public:
    static void ThreadMethod()
    {
        Console::WriteLine(
            S"Thread {0} started in {1} with AppDomainID = {2}.",
            AppDomain::GetCurrentThreadId().ToString(), 
            Thread::GetDomain()->FriendlyName, 
            Thread::GetDomainID().ToString());
    }
};

void main()
{
    Thread* newThread = 
        new Thread(new ThreadStart(0, &Test::ThreadMethod));
    newThread->Start();
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, Common Language Infrastructure (CLI) Standard

See Also

Thread Class | Thread Members | System.Threading Namespace

Show: