Threads, ThreadPool, and background work
In .NET, threads are used to run code in the background so your application stays responsive (especially important for UI apps like WPF).
What is a thread?
A thread is a single path of execution.
- The UI runs on the UI thread
- Long or blocking work should run on a background thread
❗ Never block the UI thread — your app will freeze.
Starting a thread manually
csharp
using System.Threading;
Thread thread = new Thread(() =>
{
// background work here
DoWork();
});
thread.Start();Thread Pool
using System.Threading;
ThreadPool.QueueUserWorkItem(_ =>
{
DoWork();
});