Thread.GetDomain 方法

返回当前线程正在其中运行的当前域。

**命名空间:**System.Threading
**程序集:**mscorlib(在 mscorlib.dll 中)

语法

声明
Public Shared Function GetDomain As AppDomain
用法
Dim returnValue As AppDomain

returnValue = Thread.GetDomain
public static AppDomain GetDomain ()
public:
static AppDomain^ GetDomain ()
public static AppDomain GetDomain ()
public static function GetDomain () : AppDomain

返回值

AppDomain,它表示正在运行的线程的当前应用程序域。

示例

下面的代码示例说明如何检索线程在其中运行的 AppDomain 的名称和 ID。

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

.NET Framework 并不是对每个平台的所有版本都提供支持。有关受支持版本的列表,请参见系统要求

版本信息

.NET Framework

受以下版本支持:2.0、1.1、1.0

.NET Compact Framework

受以下版本支持:2.0

请参见

参考

Thread 类
Thread 成员
System.Threading 命名空间