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

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 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0

Community Additions

ADD
Show:
© 2014 Microsoft