Thread 클래스
정의
중요
일부 정보는 릴리스되기 전에 상당 부분 수정될 수 있는 시험판 제품과 관련이 있습니다. Microsoft는 여기에 제공된 정보에 대해 어떠한 명시적이거나 묵시적인 보증도 하지 않습니다.
스레드를 만들고 제어하고, 우선 순위를 설정하고, 상태를 가져옵니다.
public ref class Thread sealed : System::Runtime::ConstrainedExecution::CriticalFinalizerObject
public ref class Thread sealed
public ref class Thread sealed : System::Runtime::InteropServices::_Thread
public ref class Thread sealed : System::Runtime::ConstrainedExecution::CriticalFinalizerObject, System::Runtime::InteropServices::_Thread
public sealed class Thread : System.Runtime.ConstrainedExecution.CriticalFinalizerObject
[System.Runtime.InteropServices.ComVisible(true)]
public sealed class Thread
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
public sealed class Thread : System.Runtime.InteropServices._Thread
[System.Runtime.InteropServices.ComVisible(true)]
[System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)]
public sealed class Thread : System.Runtime.ConstrainedExecution.CriticalFinalizerObject, System.Runtime.InteropServices._Thread
type Thread = class
inherit CriticalFinalizerObject
[<System.Runtime.InteropServices.ComVisible(true)>]
type Thread = class
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
type Thread = class
interface _Thread
[<System.Runtime.InteropServices.ComVisible(true)>]
[<System.Runtime.InteropServices.ClassInterface(System.Runtime.InteropServices.ClassInterfaceType.None)>]
type Thread = class
inherit CriticalFinalizerObject
interface _Thread
Public NotInheritable Class Thread
Inherits CriticalFinalizerObject
Public NotInheritable Class Thread
Public NotInheritable Class Thread
Implements _Thread
Public NotInheritable Class Thread
Inherits CriticalFinalizerObject
Implements _Thread
- 상속
- 상속
-
Thread
- 특성
- 구현
예제
다음 예제에서는 간단한 스레딩 기능을 보여 줍니다.
using System;
using System.Threading;
// Simple threading scenario: Start a static method running
// on a second thread.
public class ThreadExample {
// The ThreadProc method is called when the thread starts.
// It loops ten times, writing to the console and yielding
// the rest of its time slice each time, and then ends.
public static void ThreadProc() {
for (int i = 0; i < 10; i++) {
Console.WriteLine("ThreadProc: {0}", i);
// Yield the rest of the time slice.
Thread.Sleep(0);
}
}
public static void Main() {
Console.WriteLine("Main thread: Start a second thread.");
// The constructor for the Thread class requires a ThreadStart
// delegate that represents the method to be executed on the
// thread. C# simplifies the creation of this delegate.
Thread t = new Thread(new ThreadStart(ThreadProc));
// Start ThreadProc. Note that on a uniprocessor, the new
// thread does not get any processor time until the main thread
// is preempted or yields. Uncomment the Thread.Sleep that
// follows t.Start() to see the difference.
t.Start();
//Thread.Sleep(0);
for (int i = 0; i < 4; i++) {
Console.WriteLine("Main thread: Do some work.");
Thread.Sleep(0);
}
Console.WriteLine("Main thread: Call Join(), to wait until ThreadProc ends.");
t.Join();
Console.WriteLine("Main thread: ThreadProc.Join has returned. Press Enter to end program.");
Console.ReadLine();
}
}
open System.Threading
// Simple threading scenario: Start a static method running
// on a second thread.
// The ThreadProc method is called when the thread starts.
// It loops ten times, writing to the console and yielding
// the rest of its time slice each time, and then ends.
let threadProc () =
for i = 0 to 9 do
printfn $"ThreadProc: {i}"
// Yield the rest of the time slice.
Thread.Sleep 0
printfn "Main thread: Start a second thread."
// The constructor for the Thread class requires a ThreadStart
// delegate that represents the method to be executed on the
// thread. F# simplifies the creation of this delegate.
let t = Thread threadProc
// Start ThreadProc. Note that on a uniprocessor, the new
// thread does not get any processor time until the main thread
// is preempted or yields. Uncomment the Thread.Sleep that
// follows t.Start() to see the difference.
t.Start()
//Thread.Sleep 0
for _ = 0 to 3 do
printfn "Main thread: Do some work."
Thread.Sleep 0
printfn "Main thread: Call Join(), to wait until ThreadProc ends."
t.Join()
printfn "Main thread: ThreadProc.Join has returned. Press Enter to end program."
stdin.ReadLine() |> ignore
Imports System.Threading
' Simple threading scenario: Start a Shared method running
' on a second thread.
Public Class ThreadExample
' The ThreadProc method is called when the thread starts.
' It loops ten times, writing to the console and yielding
' the rest of its time slice each time, and then ends.
Public Shared Sub ThreadProc()
Dim i As Integer
For i = 0 To 9
Console.WriteLine("ThreadProc: {0}", i)
' Yield the rest of the time slice.
Thread.Sleep(0)
Next
End Sub
Public Shared Sub Main()
Console.WriteLine("Main thread: Start a second thread.")
' The constructor for the Thread class requires a ThreadStart
' delegate. The Visual Basic AddressOf operator creates this
' delegate for you.
Dim t As New Thread(AddressOf ThreadProc)
' Start ThreadProc. Note that on a uniprocessor, the new
' thread does not get any processor time until the main thread
' is preempted or yields. Uncomment the Thread.Sleep that
' follows t.Start() to see the difference.
t.Start()
'Thread.Sleep(0)
Dim i As Integer
For i = 1 To 4
Console.WriteLine("Main thread: Do some work.")
Thread.Sleep(0)
Next
Console.WriteLine("Main thread: Call Join(), to wait until ThreadProc ends.")
t.Join()
Console.WriteLine("Main thread: ThreadProc.Join has returned. Press Enter to end program.")
Console.ReadLine()
End Sub
End Class
이 코드는 다음과 유사한 출력을 생성합니다.
[VB, C++, C#]
Main thread: Start a second thread.
Main thread: Do some work.
ThreadProc: 0
Main thread: Do some work.
ThreadProc: 1
Main thread: Do some work.
ThreadProc: 2
Main thread: Do some work.
ThreadProc: 3
Main thread: Call Join(), to wait until ThreadProc ends.
ThreadProc: 4
ThreadProc: 5
ThreadProc: 6
ThreadProc: 7
ThreadProc: 8
ThreadProc: 9
Main thread: ThreadProc.Join has returned. Press Enter to end program.
설명
클래스는 Thread 스레드를 만들고 제어하며 우선 순위를 설정하고 상태를 가져옵니다.
프로세스가 시작되면 공용 언어 런타임은 애플리케이션 코드를 실행하는 단일 포그라운드 스레드를 자동으로 만듭니다. 이 기본 포그라운드 스레드와 함께 프로세스는 프로세스와 연결된 프로그램 코드의 일부를 실행하는 하나 이상의 스레드를 만들 수 있습니다. 이러한 스레드는 포그라운드 또는 백그라운드에서 실행할 수 있습니다. 또한 클래스를 ThreadPool 사용하여 공용 언어 런타임에서 관리되는 작업자 스레드에서 코드를 실행할 수 있습니다.
스레드 시작
스레드가 클래스 생성자에서 실행할 메서드를 나타내는 대리자를 제공하여 스레드를 시작합니다. 그런 다음, 메서드를 Start 호출하여 실행을 시작합니다.
Thread 생성자는 실행할 메서드에 인수를 전달할 수 있는지 여부에 따라 두 대리자 형식 중 하나를 사용할 수 있습니다.
메서드에 인수가 없는 경우 생성자에 대리자를 전달 ThreadStart 합니다. 서명이 있습니다.
public delegate void ThreadStart()Public Delegate Sub ThreadStart()다음 예제에서는 메서드를 실행하는 스레드를 만들고 시작합니다
ExecuteInForeground. 메서드는 일부 스레드 속성에 대한 정보를 표시한 다음, 루프를 실행하여 1초 반 동안 일시 중지하고 경과된 시간(초)을 표시합니다. 스레드가 5초 이상 실행되면 루프가 종료되고 스레드가 실행을 종료합니다.using System; using System.Diagnostics; using System.Threading; public class Example { public static void Main() { var th = new Thread(ExecuteInForeground); th.Start(); Thread.Sleep(1000); Console.WriteLine("Main thread ({0}) exiting...", Thread.CurrentThread.ManagedThreadId); } private static void ExecuteInForeground() { var sw = Stopwatch.StartNew(); Console.WriteLine("Thread {0}: {1}, Priority {2}", Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.ThreadState, Thread.CurrentThread.Priority); do { Console.WriteLine("Thread {0}: Elapsed {1:N2} seconds", Thread.CurrentThread.ManagedThreadId, sw.ElapsedMilliseconds / 1000.0); Thread.Sleep(500); } while (sw.ElapsedMilliseconds <= 5000); sw.Stop(); } } // The example displays output like the following: // Thread 3: Running, Priority Normal // Thread 3: Elapsed 0.00 seconds // Thread 3: Elapsed 0.51 seconds // Main thread (1) exiting... // Thread 3: Elapsed 1.02 seconds // Thread 3: Elapsed 1.53 seconds // Thread 3: Elapsed 2.05 seconds // Thread 3: Elapsed 2.55 seconds // Thread 3: Elapsed 3.07 seconds // Thread 3: Elapsed 3.57 seconds // Thread 3: Elapsed 4.07 seconds // Thread 3: Elapsed 4.58 secondsopen System.Diagnostics open System.Threading let executeInForeground () = let sw = Stopwatch.StartNew() printfn $"Thread {Thread.CurrentThread.ManagedThreadId}: {Thread.CurrentThread.ThreadState}, Priority {Thread.CurrentThread.Priority}" while sw.ElapsedMilliseconds <= 5000 do printfn $"Thread {Thread.CurrentThread.ManagedThreadId}: Elapsed {sw.ElapsedMilliseconds / 1000L:N2} seconds" Thread.Sleep 500 sw.Stop() let th = Thread executeInForeground th.Start() Thread.Sleep 1000 printfn $"Main thread ({Thread.CurrentThread.ManagedThreadId}) exiting..." // The example displays output like the following: // Thread 3: Running, Priority Normal // Thread 3: Elapsed 0.00 seconds // Thread 3: Elapsed 0.51 seconds // Main thread (1) exiting... // Thread 3: Elapsed 1.02 seconds // Thread 3: Elapsed 1.53 seconds // Thread 3: Elapsed 2.05 seconds // Thread 3: Elapsed 2.55 seconds // Thread 3: Elapsed 3.07 seconds // Thread 3: Elapsed 3.57 seconds // Thread 3: Elapsed 4.07 seconds // Thread 3: Elapsed 4.58 secondsImports System.Diagnostics Imports System.Threading Module Example3 Public Sub Main() Dim th As New Thread(AddressOf ExecuteInForeground) th.Start() Thread.Sleep(1000) Console.WriteLine("Main thread ({0}) exiting...", Thread.CurrentThread.ManagedThreadId) End Sub Private Sub ExecuteInForeground() Dim start As DateTime = DateTime.Now Dim sw As Stopwatch = Stopwatch.StartNew() Console.WriteLine("Thread {0}: {1}, Priority {2}", Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.ThreadState, Thread.CurrentThread.Priority) Do Console.WriteLine("Thread {0}: Elapsed {1:N2} seconds", Thread.CurrentThread.ManagedThreadId, sw.ElapsedMilliseconds / 1000) Thread.Sleep(500) Loop While sw.ElapsedMilliseconds <= 5000 sw.Stop() End Sub End Module ' The example displays output like the following: ' Thread 3: Running, Priority Normal ' Thread 3: Elapsed 0.00 seconds ' Thread 3: Elapsed 0.51 seconds ' Main thread (1) exiting... ' Thread 3: Elapsed 1.02 seconds ' Thread 3: Elapsed 1.53 seconds ' Thread 3: Elapsed 2.05 seconds ' Thread 3: Elapsed 2.55 seconds ' Thread 3: Elapsed 3.07 seconds ' Thread 3: Elapsed 3.57 seconds ' Thread 3: Elapsed 4.07 seconds ' Thread 3: Elapsed 4.58 seconds메서드에 인수가 있는 경우 생성자에 대리자를 전달 ParameterizedThreadStart 합니다. 서명이 있습니다.
public delegate void ParameterizedThreadStart(object obj)Public Delegate Sub ParameterizedThreadStart(obj As Object)대리자가 실행하는 메서드는 C#으로 캐스팅하거나(Visual Basic에서) 매개 변수를 적절한 형식으로 변환할 수 있습니다.
다음 예제는 생성자를 호출한다는 점을 제외하고 이전 예제와 Thread(ParameterizedThreadStart) 동일합니다. 이 버전의
ExecuteInForeground메서드에는 루프가 실행될 대략적인 시간(밀리초)을 나타내는 단일 매개 변수가 있습니다.using System; using System.Diagnostics; using System.Threading; public class Example { public static void Main() { var th = new Thread(ExecuteInForeground); th.Start(4500); Thread.Sleep(1000); Console.WriteLine("Main thread ({0}) exiting...", Thread.CurrentThread.ManagedThreadId); } private static void ExecuteInForeground(Object obj) { int interval; try { interval = (int) obj; } catch (InvalidCastException) { interval = 5000; } var sw = Stopwatch.StartNew(); Console.WriteLine("Thread {0}: {1}, Priority {2}", Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.ThreadState, Thread.CurrentThread.Priority); do { Console.WriteLine("Thread {0}: Elapsed {1:N2} seconds", Thread.CurrentThread.ManagedThreadId, sw.ElapsedMilliseconds / 1000.0); Thread.Sleep(500); } while (sw.ElapsedMilliseconds <= interval); sw.Stop(); } } // The example displays output like the following: // Thread 3: Running, Priority Normal // Thread 3: Elapsed 0.00 seconds // Thread 3: Elapsed 0.52 seconds // Main thread (1) exiting... // Thread 3: Elapsed 1.03 seconds // Thread 3: Elapsed 1.55 seconds // Thread 3: Elapsed 2.06 seconds // Thread 3: Elapsed 2.58 seconds // Thread 3: Elapsed 3.09 seconds // Thread 3: Elapsed 3.61 seconds // Thread 3: Elapsed 4.12 secondsopen System open System.Diagnostics open System.Threading let executeInForeground obj = let interval = try unbox<int> obj with :? InvalidCastException -> 5000 let sw = Stopwatch.StartNew() printfn $"Thread {Thread.CurrentThread.ManagedThreadId}: {Thread.CurrentThread.ThreadState}, Priority {Thread.CurrentThread.Priority}" while sw.ElapsedMilliseconds <= interval do printfn $"Thread {Thread.CurrentThread.ManagedThreadId}: Elapsed {sw.ElapsedMilliseconds / 1000L:N2} seconds" Thread.Sleep 500 sw.Stop() let th = Thread(ParameterizedThreadStart executeInForeground) th.Start 4500 Thread.Sleep 1000 printfn $"Main thread ({Thread.CurrentThread.ManagedThreadId}) exiting..." // The example displays output like the following: // Thread 3: Running, Priority Normal // Thread 3: Elapsed 0.00 seconds // Thread 3: Elapsed 0.52 seconds // Main thread (1) exiting... // Thread 3: Elapsed 1.03 seconds // Thread 3: Elapsed 1.55 seconds // Thread 3: Elapsed 2.06 seconds // Thread 3: Elapsed 2.58 seconds // Thread 3: Elapsed 3.09 seconds // Thread 3: Elapsed 3.61 seconds // Thread 3: Elapsed 4.12 secondsImports System.Diagnostics Imports System.Threading Module Example4 Public Sub Main() Dim th As New Thread(AddressOf ExecuteInForeground) th.Start(4500) Thread.Sleep(1000) Console.WriteLine("Main thread ({0}) exiting...", Thread.CurrentThread.ManagedThreadId) End Sub Private Sub ExecuteInForeground(obj As Object) Dim interval As Integer If IsNumeric(obj) Then interval = CInt(obj) Else interval = 5000 End If Dim start As DateTime = DateTime.Now Dim sw As Stopwatch = Stopwatch.StartNew() Console.WriteLine("Thread {0}: {1}, Priority {2}", Thread.CurrentThread.ManagedThreadId, Thread.CurrentThread.ThreadState, Thread.CurrentThread.Priority) Do Console.WriteLine("Thread {0}: Elapsed {1:N2} seconds", Thread.CurrentThread.ManagedThreadId, sw.ElapsedMilliseconds / 1000) Thread.Sleep(500) Loop While sw.ElapsedMilliseconds <= interval sw.Stop() End Sub End Module ' The example displays output like the following: ' Thread 3: Running, Priority Normal ' Thread 3: Elapsed 0.00 seconds ' Thread 3: Elapsed 0.52 seconds ' Main thread (1) exiting... ' Thread 3: Elapsed 1.03 seconds ' Thread 3: Elapsed 1.55 seconds ' Thread 3: Elapsed 2.06 seconds ' Thread 3: Elapsed 2.58 seconds ' Thread 3: Elapsed 3.09 seconds ' Thread 3: Elapsed 3.61 seconds ' Thread 3: Elapsed 4.12 seconds
스레드를 시작한 후에는 개체에 대한 참조를 Thread 유지할 필요가 없습니다. 스레드 프로시저가 완료될 때까지 스레드는 계속 실행됩니다.
스레드 개체 검색
정적(Shared Visual Basic의 경우) CurrentThread 속성을 사용하여 스레드가 실행 중인 코드에서 현재 실행 중인 스레드에 대한 참조를 검색할 수 있습니다. 다음 예제에서는 기본 애플리케이션 스레드, 다른 포그라운드 스레드, 백그라운드 스레드 및 스레드 풀 스레드에 대 한 정보를 표시 하는 속성을 사용 합니다 CurrentThread .
using System;
using System.Threading;
public class Example
{
static Object obj = new Object();
public static void Main()
{
ThreadPool.QueueUserWorkItem(ShowThreadInformation);
var th1 = new Thread(ShowThreadInformation);
th1.Start();
var th2 = new Thread(ShowThreadInformation);
th2.IsBackground = true;
th2.Start();
Thread.Sleep(500);
ShowThreadInformation(null);
}
private static void ShowThreadInformation(Object state)
{
lock (obj) {
var th = Thread.CurrentThread;
Console.WriteLine("Managed thread #{0}: ", th.ManagedThreadId);
Console.WriteLine(" Background thread: {0}", th.IsBackground);
Console.WriteLine(" Thread pool thread: {0}", th.IsThreadPoolThread);
Console.WriteLine(" Priority: {0}", th.Priority);
Console.WriteLine(" Culture: {0}", th.CurrentCulture.Name);
Console.WriteLine(" UI culture: {0}", th.CurrentUICulture.Name);
Console.WriteLine();
}
}
}
// The example displays output like the following:
// Managed thread #6:
// Background thread: True
// Thread pool thread: False
// Priority: Normal
// Culture: en-US
// UI culture: en-US
//
// Managed thread #3:
// Background thread: True
// Thread pool thread: True
// Priority: Normal
// Culture: en-US
// UI culture: en-US
//
// Managed thread #4:
// Background thread: False
// Thread pool thread: False
// Priority: Normal
// Culture: en-US
// UI culture: en-US
//
// Managed thread #1:
// Background thread: False
// Thread pool thread: False
// Priority: Normal
// Culture: en-US
// UI culture: en-US
open System.Threading
let obj = obj ()
let showThreadInformation (state: obj) =
lock obj (fun () ->
let th = Thread.CurrentThread
printfn $"Managed thread #{th.ManagedThreadId}: "
printfn $" Background thread: {th.IsBackground}"
printfn $" Thread pool thread: {th.IsThreadPoolThread}"
printfn $" Priority: {th.Priority}"
printfn $" Culture: {th.CurrentCulture.Name}"
printfn $" UI culture: {th.CurrentUICulture.Name}"
printfn "")
ThreadPool.QueueUserWorkItem showThreadInformation |> ignore
let th1 = Thread(ParameterizedThreadStart showThreadInformation)
th1.Start()
let th2 = Thread(ParameterizedThreadStart showThreadInformation)
th2.IsBackground <- true
th2.Start()
Thread.Sleep 500
showThreadInformation ()
// The example displays output like the following:
// Managed thread #6:
// Background thread: True
// Thread pool thread: False
// Priority: Normal
// Culture: en-US
// UI culture: en-US
//
// Managed thread #3:
// Background thread: True
// Thread pool thread: True
// Priority: Normal
// Culture: en-US
// UI culture: en-US
//
// Managed thread #4:
// Background thread: False
// Thread pool thread: False
// Priority: Normal
// Culture: en-US
// UI culture: en-US
//
// Managed thread #1:
// Background thread: False
// Thread pool thread: False
// Priority: Normal
// Culture: en-US
// UI culture: en-US
Imports System.Threading
Module Example2
Private lock As New Object()
Public Sub Main()
ThreadPool.QueueUserWorkItem(AddressOf ShowThreadInformation)
Dim th1 As New Thread(AddressOf ShowThreadInformation)
th1.Start()
Dim th2 As New Thread(AddressOf ShowThreadInformation)
th2.IsBackground = True
th2.Start()
Thread.Sleep(500)
ShowThreadInformation(Nothing)
End Sub
Private Sub ShowThreadInformation(state As Object)
SyncLock lock
Dim th As Thread = Thread.CurrentThread
Console.WriteLine("Managed thread #{0}: ", th.ManagedThreadId)
Console.WriteLine(" Background thread: {0}", th.IsBackground)
Console.WriteLine(" Thread pool thread: {0}", th.IsThreadPoolThread)
Console.WriteLine(" Priority: {0}", th.Priority)
Console.WriteLine(" Culture: {0}", th.CurrentCulture.Name)
Console.WriteLine(" UI culture: {0}", th.CurrentUICulture.Name)
Console.WriteLine()
End SyncLock
End Sub
End Module
' The example displays output like the following:
' ' Managed thread #6:
' Background thread: True
' Thread pool thread: False
' Priority: Normal
' Culture: en-US
' UI culture: en-US
'
' Managed thread #3:
' Background thread: True
' Thread pool thread: True
' Priority: Normal
' Culture: en-US
' UI culture: en-US
'
' Managed thread #4:
' Background thread: False
' Thread pool thread: False
' Priority: Normal
' Culture: en-US
' UI culture: en-US
'
' Managed thread #1:
' Background thread: False
' Thread pool thread: False
' Priority: Normal
' Culture: en-US
' UI culture: en-US
포그라운드 및 백그라운드 스레드
클래스의 Thread 인스턴스는 포그라운드 스레드 또는 백그라운드 스레드를 나타냅니다. 백그라운드 스레드는 한 가지 예외를 제외하고 포그라운드 스레드와 동일합니다. 백그라운드 스레드는 모든 포그라운드 스레드가 종료된 경우 프로세스를 계속 실행하지 않습니다. 모든 포그라운드 스레드가 중지되면 런타임은 모든 백그라운드 스레드를 중지하고 종료합니다.
기본적으로 다음 스레드는 포그라운드에서 실행됩니다.
주 애플리케이션 스레드입니다.
클래스 생성자를 호출 Thread 하여 만든 모든 스레드입니다.
다음 스레드는 기본적으로 백그라운드에서 실행됩니다.
런타임에 의해 유지 관리되는 작업자 스레드 풀의 스레드입니다. 클래스를 사용하여 ThreadPool 스레드 풀을 구성하고 스레드 풀 스레드에서 작업을 예약할 수 있습니다.
Note
작업 기반 비동기 작업은 스레드 풀 스레드에서 자동으로 실행됩니다. 작업 기반 비동기 작업은 클래스 Task 및 Task<TResult>를 사용하여 작업 기반 비동기 패턴을 구현합니다.
관리되지 않는 코드에서 관리되는 실행 환경을 입력하는 모든 스레드입니다.
언제든지 속성을 설정하여 백그라운드에서 실행되도록 스레드를 IsBackground 변경할 수 있습니다. 백그라운드 스레드는 애플리케이션이 실행되는 한 계속되어야 하지만 파일 시스템 변경 내용 모니터링 또는 들어오는 소켓 연결과 같이 애플리케이션이 종료되는 것을 방지해서는 안 되는 모든 작업에 유용합니다.
다음 예제에서는 포그라운드 스레드와 백그라운드 스레드의 차이점을 보여 줍니다. 스레드 시작 섹션의 첫 번째 예제와 유사합니다. 단, 스레드를 시작하기 전에 백그라운드에서 실행되도록 설정하는 것입니다. 출력에서 보여 주듯이 루프는 5초 동안 실행되기 전에 중단됩니다.
using System;
using System.Diagnostics;
using System.Threading;
public class Example
{
public static void Main()
{
var th = new Thread(ExecuteInForeground);
th.IsBackground = true;
th.Start();
Thread.Sleep(1000);
Console.WriteLine("Main thread ({0}) exiting...",
Thread.CurrentThread.ManagedThreadId);
}
private static void ExecuteInForeground()
{
var sw = Stopwatch.StartNew();
Console.WriteLine("Thread {0}: {1}, Priority {2}",
Thread.CurrentThread.ManagedThreadId,
Thread.CurrentThread.ThreadState,
Thread.CurrentThread.Priority);
do {
Console.WriteLine("Thread {0}: Elapsed {1:N2} seconds",
Thread.CurrentThread.ManagedThreadId,
sw.ElapsedMilliseconds / 1000.0);
Thread.Sleep(500);
} while (sw.ElapsedMilliseconds <= 5000);
sw.Stop();
}
}
// The example displays output like the following:
// Thread 3: Background, Priority Normal
// Thread 3: Elapsed 0.00 seconds
// Thread 3: Elapsed 0.51 seconds
// Main thread (1) exiting...
open System.Diagnostics
open System.Threading
let executeInForeground () =
let sw = Stopwatch.StartNew()
printfn $"Thread {Thread.CurrentThread.ManagedThreadId}: {Thread.CurrentThread.ThreadState}, Priority {Thread.CurrentThread.Priority}"
while sw.ElapsedMilliseconds <= 5000 do
printfn $"Thread {Thread.CurrentThread.ManagedThreadId}: Elapsed {sw.ElapsedMilliseconds / 1000L:N2} seconds"
Thread.Sleep 500
sw.Stop()
let th = Thread executeInForeground
th.IsBackground <- true
th.Start()
Thread.Sleep 1000
printfn $"Main thread ({Thread.CurrentThread.ManagedThreadId}) exiting..."
// The example displays output like the following:
// Thread 3: Background, Priority Normal
// Thread 3: Elapsed 0.00 seconds
// Thread 3: Elapsed 0.51 seconds
// Main thread (1) exiting...
Imports System.Diagnostics
Imports System.Threading
Module Example1
Public Sub Main()
Dim th As New Thread(AddressOf ExecuteInForeground)
th.IsBackground = True
th.Start()
Thread.Sleep(1000)
Console.WriteLine("Main thread ({0}) exiting...", Thread.CurrentThread.ManagedThreadId)
End Sub
Private Sub ExecuteInForeground()
Dim start As DateTime = DateTime.Now
Dim sw As Stopwatch = Stopwatch.StartNew()
Console.WriteLine("Thread {0}: {1}, Priority {2}",
Thread.CurrentThread.ManagedThreadId,
Thread.CurrentThread.ThreadState,
Thread.CurrentThread.Priority)
Do
Console.WriteLine("Thread {0}: Elapsed {1:N2} seconds",
Thread.CurrentThread.ManagedThreadId,
sw.ElapsedMilliseconds / 1000)
Thread.Sleep(500)
Loop While sw.ElapsedMilliseconds <= 5000
sw.Stop()
End Sub
End Module
' The example displays output like the following:
' Thread 3: Background, Priority Normal
' Thread 3: Elapsed 0.00 seconds
' Thread 3: Elapsed 0.51 seconds
' Main thread (1) exiting...
문화 및 주제
각 스레드에는 CurrentCulture 속성으로 표현되는 문화권과 CurrentUICulture 속성으로 표현되는 UI 문화권이 있습니다. 현재 문화권은 구문 분석 및 서식 지정, 문자열 비교 및 정렬과 같은 문화권에 민감한 작업을 지원하고 스레드에서 사용하는 쓰기 시스템과 달력을 제어합니다. 현재 UI 문화권은 리소스 파일의 리소스를 문화에 맞게 검색할 수 있도록 제공합니다.
Important
CurrentCulture 현재 스레드가 아닌 다른 스레드와 함께 사용하면 속성과 CurrentUICulture 속성이 안정적으로 작동하지 않습니다. InvalidOperationException 스레드가 다른 스레드에서 이러한 속성을 읽거나 쓰려고 하면 throw됩니다. CultureInfo.CurrentCulture 및 CultureInfo.CurrentUICulture 속성을 사용하여 현재 문화권을 검색하고 설정할 것을 권장합니다.
새 스레드가 인스턴스화되면 해당 문화권 및 UI 문화권은 새 스레드가 만들어진 스레드의 문화권 및 UI 문화권이 아니라 현재 시스템 문화권 및 UI 문화권에 의해 정의됩니다. 예를 들어 현재 시스템 문화권이 영어(미국)이고 기본 애플리케이션 스레드의 현재 문화권이 프랑스어(프랑스)인 경우 기본 스레드에서 생성자를 호출 Thread(ParameterizedThreadStart) 하여 만든 새 스레드의 문화권은 프랑스어(프랑스)가 아닌 영어(미국)입니다. 자세한 내용은 클래스 항목의 "문화권 및 스레드" 섹션을 CultureInfo 참조하세요.
Important
.NET Framework 4.6 이상 버전을 대상으로 하는 앱에 대해 비동기 작업을 실행하는 스레드의 경우는 그렇지 않습니다. 이 경우 문화권 및 UI 문화권은 비동기 작업의 컨텍스트에 속합니다. 기본적으로 비동기 작업이 실행되는 스레드는 비동기 작업이 시작된 스레드의 문화권 및 UI 문화권을 상속합니다. 자세한 내용은 클래스 설명의 "문화권 및 작업 기반 비동기 작업" 섹션을 CultureInfo 참조하세요.
다음 중 하나를 수행하여 애플리케이션에서 실행되는 모든 스레드가 동일한 문화권 및 UI 문화권을 공유하도록 할 수 있습니다.
CultureInfo 객체를 해당 문화권을 나타내도록 하여 ParameterizedThreadStart 대리자나 ThreadPool.QueueUserWorkItem(WaitCallback, Object) 메서드에 전달할 수 있습니다.
.NET Framework 4.5 이상 버전에서 실행되는 앱의 경우, 애플리케이션 도메인 안에서 생성되는 모든 스레드에 할당할 문화권 및 UI 문화권을 CultureInfo.DefaultThreadCurrentCulture 및 CultureInfo.DefaultThreadCurrentUICulture 속성 값을 설정하여 정의할 수 있습니다. 애플리케이션별 도메인 설정입니다.
자세한 내용 및 예제는 클래스 설명의 "문화권 및 스레드" 섹션을 CultureInfo 참조하세요.
스레드에 대한 정보 가져오기 및 제어
스레드에 대한 정보를 제공하는 여러 속성 값을 검색할 수 있습니다. 경우에 따라 이러한 속성 값을 설정하여 스레드의 작업을 제어할 수도 있습니다. 이러한 스레드 속성은 다음과 같습니다.
이름입니다. Name 는 스레드를 식별하는 데 사용할 수 있는 쓰기-한 번 속성입니다. 기본값은 입니다
null.메서드를 호출하여 검색할 수 있는 해시 코드입니다 GetHashCode . 해시 코드를 사용하여 스레드를 고유하게 식별할 수 있습니다. 스레드의 수명 동안 해당 해시 코드는 값을 가져오는 애플리케이션 도메인에 관계없이 다른 스레드의 값과 충돌하지 않습니다.
스레드 ID입니다. 읽기 전용 ManagedThreadId 속성의 값은 런타임에서 할당되며 프로세스 내에서 스레드를 고유하게 식별합니다.
Note
관리되지 않는 호스트는 관리되는 스레드와 관리되지 않는 스레드 간의 관계를 제어할 수 있으므로 운영 체제 ThreadId 에는 관리되는 스레드에 대한 고정된 관계가 없습니다. 특히 정교한 호스트는 CLR 호스팅 API 를 사용하여 동일한 운영 체제 스레드에 대해 많은 관리되는 스레드를 예약하거나 다른 운영 체제 스레드 간에 관리되는 스레드를 이동할 수 있습니다.
스레드의 현재 상태입니다. 스레드가 존재하는 동안에는 항상 속성에서 정의한 상태 중 하나 이상에 있습니다 ThreadState .
속성에 의해 ThreadPriority 정의된 예약 우선 순위 수준입니다. 스레드의 우선 순위를 요청하도록 이 값을 설정할 수 있지만 운영 체제에서 적용할 수 있는 것은 아닙니다.
스레드가 스레드 풀 스레드인지 여부를 나타내는 읽기 전용 IsThreadPoolThread 속성입니다.
IsBackground 속성입니다. 자세한 내용은 포그라운드 및 백그라운드 스레드 섹션을 참조하세요 .
생성자
| Name | Description |
|---|---|
| Thread(ParameterizedThreadStart, Int32) |
스레드가 시작될 때 개체를 스레드에 전달할 수 있는 대리자를 지정하고 스레드의 최대 스택 크기를 지정하여 클래스의 새 인스턴스 Thread 를 초기화합니다. |
| Thread(ParameterizedThreadStart) |
스레드가 시작될 때 개체를 스레드에 전달할 수 있는 대리자를 지정하여 클래스의 새 인스턴스 Thread 를 초기화합니다. |
| Thread(ThreadStart, Int32) |
스레드의 최대 스택 크기를 지정하여 클래스의 Thread 새 인스턴스를 초기화합니다. |
| Thread(ThreadStart) |
Thread 클래스의 새 인스턴스를 초기화합니다. |
속성
| Name | Description |
|---|---|
| ApartmentState |
사용되지 않음.
사용되지 않음.
이 스레드의 아파트 상태를 가져오거나 설정합니다. |
| CurrentContext |
스레드가 실행 중인 현재 컨텍스트를 가져옵니다. |
| CurrentCulture |
현재 스레드의 문화권을 가져오거나 설정합니다. |
| CurrentPrincipal |
스레드의 현재 보안 주체(역할 기반 보안용)를 가져오거나 설정합니다. |
| CurrentThread |
현재 실행 중인 스레드를 가져옵니다. |
| CurrentUICulture |
Resource Manager에서 런타임에 문화권별 리소스를 조회하는 데 사용하는 현재 문화권을 가져오거나 설정합니다. |
| ExecutionContext |
현재 스레드의 ExecutionContext 다양한 컨텍스트에 대한 정보를 포함하는 개체를 가져옵니다. |
| IsAlive |
현재 스레드의 실행 상태를 나타내는 값을 가져옵니다. |
| IsBackground |
스레드가 백그라운드 스레드인지 여부를 나타내는 값을 가져오거나 설정합니다. |
| IsThreadPoolThread |
스레드가 관리되는 스레드 풀에 속하는지 여부를 나타내는 값을 가져옵니다. |
| ManagedThreadId |
현재 관리되는 스레드에 대한 고유 식별자를 가져옵니다. |
| Name |
스레드의 이름을 가져오거나 설정합니다. |
| Priority |
스레드의 예약 우선 순위를 나타내는 값을 가져오거나 설정합니다. |
| ThreadState |
현재 스레드의 상태를 포함하는 값을 가져옵니다. |
메서드
| Name | Description |
|---|---|
| Abort() |
사용되지 않음.
스레드를 ThreadAbortException 종료하는 프로세스를 시작하기 위해 호출되는 스레드에서 발생합니다. 이 메서드를 호출하면 일반적으로 스레드가 종료됩니다. |
| Abort(Object) |
사용되지 않음.
ThreadAbortException 스레드 종료에 대한 예외 정보도 제공하면서 스레드를 종료하는 프로세스를 시작하기 위해 스레드가 호출되는 스레드에서 발생합니다. 이 메서드를 호출하면 일반적으로 스레드가 종료됩니다. |
| AllocateDataSlot() |
모든 스레드에 명명되지 않은 데이터 슬롯을 할당합니다. 성능을 향상시키려면 특성으로 ThreadStaticAttribute 표시된 필드를 대신 사용합니다. |
| AllocateNamedDataSlot(String) |
모든 스레드에 명명된 데이터 슬롯을 할당합니다. 성능을 향상시키려면 특성으로 ThreadStaticAttribute 표시된 필드를 대신 사용합니다. |
| BeginCriticalRegion() |
실행이 스레드 중단 또는 처리되지 않은 예외의 영향으로 애플리케이션 도메인의 다른 작업이 위태로울 수 있는 코드 영역을 입력하려고 한다는 것을 호스트에 알렸습니다. |
| BeginThreadAffinity() |
호스트에 관리 코드가 현재 물리적 운영 체제 스레드의 ID에 따라 달라지는 명령을 실행하려고 했음을 알 수 있습니다. |
| DisableComObjectEagerCleanup() |
현재 스레드에 대한 RCW(런타임 호출 가능 래퍼)의 자동 정리를 해제합니다. |
| EndCriticalRegion() |
실행이 스레드 중단 또는 처리되지 않은 예외의 영향이 현재 작업으로 제한되는 코드 영역을 입력하려고 한다는 것을 호스트에 알렸습니다. |
| EndThreadAffinity() |
호스트에 관리 코드가 현재 물리적 운영 체제 스레드의 ID에 따라 달라지는 명령 실행을 완료했음을 알 수 있습니다. |
| Equals(Object) |
지정된 개체가 현재 개체와 같은지 여부를 확인합니다. (다음에서 상속됨 Object) |
| Finalize() |
가비지 수집기가 개체를 회수할 때 리소스가 해제되고 다른 정리 작업이 수행되도록 합니다 Thread . |
| FreeNamedDataSlot(String) |
프로세스의 모든 스레드에 대해 이름과 슬롯 간의 연결을 제거합니다. 성능을 향상시키려면 특성으로 ThreadStaticAttribute 표시된 필드를 대신 사용합니다. |
| GetApartmentState() |
ApartmentState 아파트 상태를 나타내는 값을 반환합니다. |
| GetCompressedStack() |
사용되지 않음.
사용되지 않음.
현재 스레드의 CompressedStack 스택을 캡처하는 데 사용할 수 있는 개체를 반환합니다. |
| GetCurrentProcessorId() |
현재 스레드가 실행 중인 프로세서를 나타내는 데 사용되는 ID를 가져옵니다. |
| GetData(LocalDataStoreSlot) |
현재 스레드의 현재 도메인 내에서 현재 스레드의 지정된 슬롯에서 값을 검색합니다. 성능을 향상시키려면 특성으로 ThreadStaticAttribute 표시된 필드를 대신 사용합니다. |
| GetDomain() |
현재 스레드가 실행 중인 현재 도메인을 반환합니다. |
| GetDomainID() |
고유한 애플리케이션 도메인 식별자를 반환합니다. |
| GetHashCode() |
현재 스레드에 대한 해시 코드를 반환합니다. |
| GetHashCode() |
기본 해시 함수로 사용됩니다. (다음에서 상속됨 Object) |
| GetNamedDataSlot(String) |
명명된 데이터 슬롯을 조회합니다. 성능을 향상시키려면 특성으로 ThreadStaticAttribute 표시된 필드를 대신 사용합니다. |
| GetType() |
현재 인스턴스의 Type 가져옵니다. (다음에서 상속됨 Object) |
| Interrupt() |
스레드 상태에 있는 스레드를 WaitSleepJoin 중단합니다. |
| Join() |
표준 COM 및 |
| Join(Int32) |
표준 COM 및 SendMessage 펌핑을 계속 수행하면서 이 인스턴스가 나타내는 스레드가 종료되거나 지정된 시간이 경과할 때까지 호출 스레드를 차단합니다. |
| Join(TimeSpan) |
표준 COM 및 SendMessage 펌핑을 계속 수행하면서 이 인스턴스가 나타내는 스레드가 종료되거나 지정된 시간이 경과할 때까지 호출 스레드를 차단합니다. |
| MemberwiseClone() |
현재 Object단순 복사본을 만듭니다. (다음에서 상속됨 Object) |
| MemoryBarrier() |
다음과 같이 메모리 액세스를 동기화합니다. 현재 스레드를 실행하는 프로세서는 호출 후 메모리에 액세스한 후 실행하기 위해 호출하기 전에 메모리가 액세스하는 MemoryBarrier() 방식으로 명령을 다시 정렬할 MemoryBarrier()수 없습니다. |
| ResetAbort() |
사용되지 않음.
현재 스레드에 대한 요청된 Abort(Object) 내용을 취소합니다. |
| Resume() |
사용되지 않음.
사용되지 않음.
사용되지 않음.
일시 중단된 스레드를 다시 시작합니다. |
| SetApartmentState(ApartmentState) |
스레드가 시작되기 전에 스레드의 아파트 상태를 설정합니다. |
| SetCompressedStack(CompressedStack) |
사용되지 않음.
사용되지 않음.
캡처된 CompressedStack 개체를 현재 스레드에 적용합니다. |
| SetData(LocalDataStoreSlot, Object) |
해당 스레드의 현재 도메인에 대해 현재 실행 중인 스레드의 지정된 슬롯에 있는 데이터를 설정합니다. 성능을 향상시키려면 특성으로 ThreadStaticAttribute 표시된 필드를 대신 사용합니다. |
| Sleep(Int32) |
지정된 시간(밀리초)에 대한 현재 스레드를 일시 중단합니다. |
| Sleep(TimeSpan) |
지정된 시간 동안 현재 스레드를 일시 중단합니다. |
| SpinWait(Int32) |
스레드가 매개 변수로 정의된 횟수를 대기하게 합니다 |
| Start() |
운영 체제에서 현재 인스턴스의 상태를 .로 변경합니다 Running. |
| Start(Object) |
운영 체제에서 현재 인스턴스의 상태를 변경하고 Running필요에 따라 스레드가 실행하는 메서드에서 사용할 데이터가 포함된 개체를 제공합니다. |
| Suspend() |
사용되지 않음.
사용되지 않음.
사용되지 않음.
스레드를 일시 중단하거나 스레드가 이미 일시 중단된 경우에는 아무런 효과가 없습니다. |
| ToString() |
현재 개체를 나타내는 문자열을 반환합니다. (다음에서 상속됨 Object) |
| TrySetApartmentState(ApartmentState) |
스레드가 시작되기 전에 스레드의 아파트 상태를 설정합니다. |
| UnsafeStart() |
운영 체제에서 현재 인스턴스의 상태를 .로 변경합니다 Running. |
| UnsafeStart(Object) |
운영 체제에서 현재 인스턴스의 상태를 변경하고 Running필요에 따라 스레드가 실행하는 메서드에서 사용할 데이터가 포함된 개체를 제공합니다. |
| VolatileRead(Byte) |
사용되지 않음.
필드 값을 읽습니다. 필요한 시스템에서는 다음과 같이 프로세서가 메모리 작업을 다시 정렬하지 못하도록 하는 메모리 장벽을 삽입합니다. 코드에서 이 메서드 뒤에 읽기 또는 쓰기가 나타나면 프로세서가 이 메서드 앞에 이동할 수 없습니다. |
| VolatileRead(Double) |
사용되지 않음.
필드 값을 읽습니다. 필요한 시스템에서는 다음과 같이 프로세서가 메모리 작업을 다시 정렬하지 못하도록 하는 메모리 장벽을 삽입합니다. 코드에서 이 메서드 뒤에 읽기 또는 쓰기가 나타나면 프로세서가 이 메서드 앞에 이동할 수 없습니다. |
| VolatileRead(Int16) |
사용되지 않음.
필드 값을 읽습니다. 필요한 시스템에서는 다음과 같이 프로세서가 메모리 작업을 다시 정렬하지 못하도록 하는 메모리 장벽을 삽입합니다. 코드에서 이 메서드 뒤에 읽기 또는 쓰기가 나타나면 프로세서가 이 메서드 앞에 이동할 수 없습니다. |
| VolatileRead(Int32) |
사용되지 않음.
필드 값을 읽습니다. 필요한 시스템에서는 다음과 같이 프로세서가 메모리 작업을 다시 정렬하지 못하도록 하는 메모리 장벽을 삽입합니다. 코드에서 이 메서드 뒤에 읽기 또는 쓰기가 나타나면 프로세서가 이 메서드 앞에 이동할 수 없습니다. |
| VolatileRead(Int64) |
사용되지 않음.
필드 값을 읽습니다. 필요한 시스템에서는 다음과 같이 프로세서가 메모리 작업을 다시 정렬하지 못하도록 하는 메모리 장벽을 삽입합니다. 코드에서 이 메서드 뒤에 읽기 또는 쓰기가 나타나면 프로세서가 이 메서드 앞에 이동할 수 없습니다. |
| VolatileRead(IntPtr) |
사용되지 않음.
필드 값을 읽습니다. 필요한 시스템에서는 다음과 같이 프로세서가 메모리 작업을 다시 정렬하지 못하도록 하는 메모리 장벽을 삽입합니다. 코드에서 이 메서드 뒤에 읽기 또는 쓰기가 나타나면 프로세서가 이 메서드 앞에 이동할 수 없습니다. |
| VolatileRead(Object) |
사용되지 않음.
필드 값을 읽습니다. 필요한 시스템에서는 다음과 같이 프로세서가 메모리 작업을 다시 정렬하지 못하도록 하는 메모리 장벽을 삽입합니다. 코드에서 이 메서드 뒤에 읽기 또는 쓰기가 나타나면 프로세서가 이 메서드 앞에 이동할 수 없습니다. |
| VolatileRead(SByte) |
사용되지 않음.
필드 값을 읽습니다. 필요한 시스템에서는 다음과 같이 프로세서가 메모리 작업을 다시 정렬하지 못하도록 하는 메모리 장벽을 삽입합니다. 코드에서 이 메서드 뒤에 읽기 또는 쓰기가 나타나면 프로세서가 이 메서드 앞에 이동할 수 없습니다. |
| VolatileRead(Single) |
사용되지 않음.
필드 값을 읽습니다. 필요한 시스템에서는 다음과 같이 프로세서가 메모리 작업을 다시 정렬하지 못하도록 하는 메모리 장벽을 삽입합니다. 코드에서 이 메서드 뒤에 읽기 또는 쓰기가 나타나면 프로세서가 이 메서드 앞에 이동할 수 없습니다. |
| VolatileRead(UInt16) |
사용되지 않음.
필드 값을 읽습니다. 필요한 시스템에서는 다음과 같이 프로세서가 메모리 작업을 다시 정렬하지 못하도록 하는 메모리 장벽을 삽입합니다. 코드에서 이 메서드 뒤에 읽기 또는 쓰기가 나타나면 프로세서가 이 메서드 앞에 이동할 수 없습니다. |
| VolatileRead(UInt32) |
사용되지 않음.
필드 값을 읽습니다. 필요한 시스템에서는 다음과 같이 프로세서가 메모리 작업을 다시 정렬하지 못하도록 하는 메모리 장벽을 삽입합니다. 코드에서 이 메서드 뒤에 읽기 또는 쓰기가 나타나면 프로세서가 이 메서드 앞에 이동할 수 없습니다. |
| VolatileRead(UInt64) |
사용되지 않음.
필드 값을 읽습니다. 필요한 시스템에서는 다음과 같이 프로세서가 메모리 작업을 다시 정렬하지 못하도록 하는 메모리 장벽을 삽입합니다. 코드에서 이 메서드 뒤에 읽기 또는 쓰기가 나타나면 프로세서가 이 메서드 앞에 이동할 수 없습니다. |
| VolatileRead(UIntPtr) |
사용되지 않음.
필드 값을 읽습니다. 필요한 시스템에서는 다음과 같이 프로세서가 메모리 작업을 다시 정렬하지 못하도록 하는 메모리 장벽을 삽입합니다. 코드에서 이 메서드 뒤에 읽기 또는 쓰기가 나타나면 프로세서가 이 메서드 앞에 이동할 수 없습니다. |
| VolatileWrite(Byte, Byte) |
사용되지 않음.
필드에 값을 씁니다. 이를 필요로 하는 시스템에서는 다음과 같이 프로세서가 메모리 작업의 순서를 다시 지정하지 못하도록 하는 메모리 장벽을 삽입합니다. 코드에서 이 메서드 앞에 읽기 또는 쓰기가 나타나면 프로세서는 이 메서드를 따라 이동할 수 없습니다. |
| VolatileWrite(Double, Double) |
사용되지 않음.
필드에 값을 씁니다. 이를 필요로 하는 시스템에서는 다음과 같이 프로세서가 메모리 작업의 순서를 다시 지정하지 못하도록 하는 메모리 장벽을 삽입합니다. 코드에서 이 메서드 앞에 읽기 또는 쓰기가 나타나면 프로세서는 이 메서드를 따라 이동할 수 없습니다. |
| VolatileWrite(Int16, Int16) |
사용되지 않음.
필드에 값을 씁니다. 이를 필요로 하는 시스템에서는 다음과 같이 프로세서가 메모리 작업의 순서를 다시 지정하지 못하도록 하는 메모리 장벽을 삽입합니다. 코드에서 이 메서드 앞에 읽기 또는 쓰기가 나타나면 프로세서는 이 메서드를 따라 이동할 수 없습니다. |
| VolatileWrite(Int32, Int32) |
사용되지 않음.
필드에 값을 씁니다. 이를 필요로 하는 시스템에서는 다음과 같이 프로세서가 메모리 작업의 순서를 다시 지정하지 못하도록 하는 메모리 장벽을 삽입합니다. 코드에서 이 메서드 앞에 읽기 또는 쓰기가 나타나면 프로세서는 이 메서드를 따라 이동할 수 없습니다. |
| VolatileWrite(Int64, Int64) |
사용되지 않음.
필드에 값을 씁니다. 이를 필요로 하는 시스템에서는 다음과 같이 프로세서가 메모리 작업의 순서를 다시 지정하지 못하도록 하는 메모리 장벽을 삽입합니다. 코드에서 이 메서드 앞에 읽기 또는 쓰기가 나타나면 프로세서는 이 메서드를 따라 이동할 수 없습니다. |
| VolatileWrite(IntPtr, IntPtr) |
사용되지 않음.
필드에 값을 씁니다. 이를 필요로 하는 시스템에서는 다음과 같이 프로세서가 메모리 작업의 순서를 다시 지정하지 못하도록 하는 메모리 장벽을 삽입합니다. 코드에서 이 메서드 앞에 읽기 또는 쓰기가 나타나면 프로세서는 이 메서드를 따라 이동할 수 없습니다. |
| VolatileWrite(Object, Object) |
사용되지 않음.
필드에 값을 씁니다. 이를 필요로 하는 시스템에서는 다음과 같이 프로세서가 메모리 작업의 순서를 다시 지정하지 못하도록 하는 메모리 장벽을 삽입합니다. 코드에서 이 메서드 앞에 읽기 또는 쓰기가 나타나면 프로세서는 이 메서드를 따라 이동할 수 없습니다. |
| VolatileWrite(SByte, SByte) |
사용되지 않음.
필드에 값을 씁니다. 이를 필요로 하는 시스템에서는 다음과 같이 프로세서가 메모리 작업의 순서를 다시 지정하지 못하도록 하는 메모리 장벽을 삽입합니다. 코드에서 이 메서드 앞에 읽기 또는 쓰기가 나타나면 프로세서는 이 메서드를 따라 이동할 수 없습니다. |
| VolatileWrite(Single, Single) |
사용되지 않음.
필드에 값을 씁니다. 이를 필요로 하는 시스템에서는 다음과 같이 프로세서가 메모리 작업의 순서를 다시 지정하지 못하도록 하는 메모리 장벽을 삽입합니다. 코드에서 이 메서드 앞에 읽기 또는 쓰기가 나타나면 프로세서는 이 메서드를 따라 이동할 수 없습니다. |
| VolatileWrite(UInt16, UInt16) |
사용되지 않음.
필드에 값을 씁니다. 이를 필요로 하는 시스템에서는 다음과 같이 프로세서가 메모리 작업의 순서를 다시 지정하지 못하도록 하는 메모리 장벽을 삽입합니다. 코드에서 이 메서드 앞에 읽기 또는 쓰기가 나타나면 프로세서는 이 메서드를 따라 이동할 수 없습니다. |
| VolatileWrite(UInt32, UInt32) |
사용되지 않음.
필드에 값을 씁니다. 이를 필요로 하는 시스템에서는 다음과 같이 프로세서가 메모리 작업의 순서를 다시 지정하지 못하도록 하는 메모리 장벽을 삽입합니다. 코드에서 이 메서드 앞에 읽기 또는 쓰기가 나타나면 프로세서는 이 메서드를 따라 이동할 수 없습니다. |
| VolatileWrite(UInt64, UInt64) |
사용되지 않음.
필드에 값을 씁니다. 이를 필요로 하는 시스템에서는 다음과 같이 프로세서가 메모리 작업의 순서를 다시 지정하지 못하도록 하는 메모리 장벽을 삽입합니다. 코드에서 이 메서드 앞에 읽기 또는 쓰기가 나타나면 프로세서는 이 메서드를 따라 이동할 수 없습니다. |
| VolatileWrite(UIntPtr, UIntPtr) |
사용되지 않음.
필드에 값을 씁니다. 이를 필요로 하는 시스템에서는 다음과 같이 프로세서가 메모리 작업의 순서를 다시 지정하지 못하도록 하는 메모리 장벽을 삽입합니다. 코드에서 이 메서드 앞에 읽기 또는 쓰기가 나타나면 프로세서는 이 메서드를 따라 이동할 수 없습니다. |
| Yield() |
호출 스레드가 현재 프로세서에서 실행할 준비가 되어 있는 다른 스레드에 실행 명령을 내리도록 합니다. 운영 체제에서 생성할 스레드를 선택합니다. |
명시적 인터페이스 구현
| Name | Description |
|---|---|
| _Thread.GetIDsOfNames(Guid, IntPtr, UInt32, UInt32, IntPtr) |
이름 집합을 해당 디스패치 식별자 집합에 매핑합니다. |
| _Thread.GetTypeInfo(UInt32, UInt32, IntPtr) |
인터페이스의 형식 정보를 가져오는 데 사용할 수 있는 개체의 형식 정보를 검색합니다. |
| _Thread.GetTypeInfoCount(UInt32) |
개체가 제공하는 형식 정보 인터페이스의 수를 검색합니다(0 또는 1). |
| _Thread.Invoke(UInt32, Guid, UInt32, Int16, IntPtr, IntPtr, IntPtr, IntPtr) |
개체에 의해 노출되는 속성 및 메서드에 대한 액세스를 제공합니다. |
적용 대상
스레드 보안
이 형식은 스레드로부터 안전합니다.