What is the difference between Task and Thread in C#?
Answer
A Thread is a low-level OS-managed execution unit — each thread has its own stack, takes 1MB+ of memory, and switching between threads (context switching) is expensive. Creating and managing threads manually is complex (synchronization, deadlocks). A Task is a higher-level abstraction built on the ThreadPool — it represents an asynchronous operation, managed by the runtime. Tasks are lightweight (no dedicated stack), pooled (threads are reused), and composable (continuations, Task.WhenAll, Task.WhenAny). Prefer Tasks over raw Threads for almost all scenarios. Use raw threads only when: you need control over thread priority, apartment state (COM interop), or very long-running dedicated work (even then, prefer Thread with IsBackground = true). Task.Run(() => ...) queues work to the ThreadPool. async/await is built on Tasks.