Thread.GetDomainID 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
傳回唯一的應用程式定義域識別項。
public:
static int GetDomainID();
public static int GetDomainID ();
static member GetDomainID : unit -> int
Public Shared Function GetDomainID () As Integer
傳回
唯一識別應用程式定義域的 32 位元帶正負號的整數 (Signed Integer)。
範例
下列程式碼範例示範如何擷取執行緒執行所在之 的名稱 AppDomain
和識別碼。
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();
}
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());
}
}
open System
open System.Threading
let threadMethod () =
printfn $"Thread {AppDomain.GetCurrentThreadId()} started in {Thread.GetDomain().FriendlyName} with AppDomainID = {Thread.GetDomainID()}."
let newThread = Thread threadMethod
newThread.Start()
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