Thread.GetDomain メソッド

現在のスレッドが実行されている現在のドメインを返します。

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

戻り値

実行中のスレッドの現在のアプリケーション ドメインを表す AppDomain

解説

get アクセサと set アクセサは、論理スレッドではなくハード スレッドで機能します。このため、これらのアクセサはパッケージ保護されており、通常の消費量では利用できません。

使用例

[Visual Basic, C#, C++] スレッドが実行されている AppDomain の名前と ID を取得する方法の例を次に示します。

 
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] JScript のサンプルはありません。Visual Basic、C#、および C++ のサンプルを表示するには、このページの左上隅にある言語のフィルタ ボタン 言語のフィルタ をクリックします。

必要条件

プラットフォーム: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 ファミリ, Common Language Infrastructure (CLI) Standard

参照

Thread クラス | Thread メンバ | System.Threading 名前空間