Thread.Name プロパティ
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
スレッドの名前を取得または設定します。
public:
property System::String ^ Name { System::String ^ get(); void set(System::String ^ value); };
public string? Name { get; set; }
public string Name { get; set; }
member this.Name : string with get, set
Public Property Name As String
プロパティ値
スレッドの名前を含む文字列。名前が設定されていない場合は null
。
例外
設定操作が要求されましたが、Name
プロパティは既に設定されています。
例
次の例は、スレッドに名前を付ける方法を示しています。
using namespace System;
using namespace System::Threading;
int main()
{
// Check whether the thread has previously been named to
// avoid a possible InvalidOperationException.
if ( Thread::CurrentThread->Name == nullptr )
{
Thread::CurrentThread->Name = "MainThread";
}
else
{
Console::WriteLine( "Unable to name a previously "
"named thread." );
}
}
using System;
using System.Threading;
class Name
{
static void Main()
{
// Check whether the thread has previously been named
// to avoid a possible InvalidOperationException.
if(Thread.CurrentThread.Name == null)
{
Thread.CurrentThread.Name = "MainThread";
}
else
{
Console.WriteLine("Unable to name a previously " +
"named thread.");
}
}
}
Imports System.Threading
Public Class Name
<MTAThread> _
Shared Sub Main()
' Check whether the thread has previously been named
' to avoid a possible InvalidOperationException.
If Thread.CurrentThread.Name = Nothing Then
Thread.CurrentThread.Name = "MainThread"
Else
Console.WriteLine("Unable to name a previously " & _
"named thread.")
End If
End Sub
End Class
注釈
このプロパティは write-once です。 スレッド Name のプロパティの既定値は null
、スレッドに対して既に明示的に割り当てられているかどうかを判断するには、スレッドと null
比較します。
プロパティに割り当てられた文字列には、任意の Name Unicode 文字を含めることができます。