Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

Thread.GetDomain Method

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

Namespace: System.Threading
Assembly: mscorlib (in mscorlib.dll)

public static AppDomain GetDomain ()
public static AppDomain GetDomain ()
public static function GetDomain () : AppDomain
Not applicable.

Return Value

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

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

import System.*;
import System.Threading.*;
import System.Threading.Thread;

class Test
{
    public static void main(String[] args)
    {
        Thread newThread = new Thread(new ThreadStart(ThreadMethod));

        newThread.Start();
    } //main

    static void ThreadMethod()
    {
        Console.WriteLine("Thread {0} started in {1} with AppDomainID = {2}.",
            String.valueOf(AppDomain.GetCurrentThreadId()),
            Thread.GetDomain().get_FriendlyName(),
            String.valueOf(Thread.GetDomainID()));
    } //ThreadMethod
} //Test

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

XNA Framework

Supported in: 1.0

Community Additions

ADD
Show:
© 2015 Microsoft