Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C#

Thread — starting a thread, waiting, and culture settings

Thread lets you create and control threads directly. Learn the difference between Start and Join, how to access the current thread, and the separate roles of CurrentCulture and CurrentUICulture.

Version: .NET 10; repository net10.0 and LangVersion=preview; feature versions require per-entry verification

Syntax

Thread worker = new Thread(() => { /* work */ });
worker.Start();
worker.Join();
Thread current = Thread.CurrentThread;
current.CurrentCulture = CultureInfo.InvariantCulture;
current.CurrentUICulture = CultureInfo.InvariantCulture;

Thread in System.Threading represents a managed thread. Its constructor accepts a delegate describing the work, but new Thread(...) alone does not run it. Thread.Start schedules the thread for execution; it does not guarantee an immediate start. Each object can be started only once, even after its thread has terminated. These APIs are available in .NET 10 and do not require preview language features.

Thread.Join() blocks the calling thread until the target thread terminates. Timeout overloads return bool: true means the thread terminated, and false means the timeout elapsed. Do not call an indefinite Join() on the current thread—it would wait for itself. Blocking waits on a user-interface thread can freeze the interface.

The static Thread.CurrentThread property returns the object representing the thread executing the code. Its Thread.CurrentCulture controls operations such as formatting and parsing numbers and dates, whereas Thread.CurrentUICulture determines the culture used to look up localized resources. These settings are independent: the UI culture does not set the decimal separator. In .NET 10, reading or writing these properties for another thread throws InvalidOperationException. The documentation recommends CultureInfo.CurrentCulture and CultureInfo.CurrentUICulture for managing the culture of the current execution.

The example explicitly sets both cultures inside the worker thread to CultureInfo.InvariantCulture rather than relying on environment settings. The F2 format produces 1234.50, and Join() ensures that Worker finished. is printed only after the worker's messages. No delays or scheduling-order assumptions are used.

Examples

using System;
using System.Globalization;
using System.Threading;

internal static class Program
{
    private static void Main()
    {
        Thread worker = new Thread(() =>
        {
            Thread current = Thread.CurrentThread;
            current.CurrentCulture = CultureInfo.InvariantCulture;
            current.CurrentUICulture = CultureInfo.InvariantCulture;

            Console.WriteLine($"Value: {1234.5m:F2}");
            Console.WriteLine($"Invariant UI: {current.CurrentUICulture.Equals(CultureInfo.InvariantCulture)}");
        });

        worker.Start();
        worker.Join();
        Console.WriteLine("Worker finished.");
    }
}

Result

Value: 1234.50
Invariant UI: True
Worker finished.

The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.

Sources