📁 Sangam Dhakal - Portfolio v2.0 - Netscape Navigator 4.0
_
□
×

πŸ“š .NET Interview Questions

377 questions for senior .NET engineer interviews, each with a 30-second answer, the full answer, a deep dive, the follow-ups interviewers ask next, and real-world production problems.

Phase 6 — Asynchronous Programming and Multithreading

Threads, tasks, synchronisation primitives, advanced async patterns and the concurrency problems seen in production .NET systems.

  1. What is a Thread in .NET, and when would you still create one directly instead of using Task.Run or the ThreadPool?

    System.Threading.Thread: what it maps to, its cost, its API surface in .NET 10 and the narrow cases where a dedicated thread is the right choice.

    Mid-Level Theory Threads Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  2. Walk me through the lifecycle of a .NET thread. What states can it be in, and what happens on each transition?

    ThreadState values, legal transitions, Join, Sleep, Interrupt and how a thread ends, including unhandled exceptions.

    Mid-Level Theory Threads Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  3. What is the difference between a foreground thread and a background thread in .NET, and why does it matter at shutdown?

    IsBackground, which threads are background by default, process exit rules and graceful shutdown in hosted apps.

    Junior Theory Threads Β· πŸ”— 2 follow-ups
  4. How does the .NET ThreadPool work, and how does it decide how many threads to run?

    Global and local queues, work stealing, minimum threads, hill climbing, starvation injection and the metrics to watch in .NET 10.

    Senior Theory Threads Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  5. What is the difference between ThreadPool worker threads and I/O completion threads, and does it matter on Linux?

    Worker versus completion-port threads, IOCP on Windows, epoll on Linux, how async I/O completes without a thread waiting, and what GetAvailableThreads really reports.

    Senior Theory Threads Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  6. How does thread-local storage work in .NET? Compare [ThreadStatic], ThreadLocal of T and AsyncLocal of T.

    Per-thread state with ThreadStatic and ThreadLocal, why it breaks across await, and how AsyncLocal flows with ExecutionContext.

    Senior Theory Threads Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  7. What is a Task in .NET? Is a Task the same as a thread?

    Task as a promise of completion, delegate tasks versus promise tasks, TaskStatus, and the core combinators in .NET 10.

    Mid-Level Theory Tasks Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  8. How does Task of T differ from Task, and what should you know about getting its result safely?

    `Task<T>` results, await versus .Result versus GetAwaiter().GetResult(), TaskCompletionSource of T, cached completed tasks and why `Task<T>` is not covariant.

    Mid-Level Theory Tasks Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  9. What is ValueTask, when should you use it instead of Task, and what rules must callers follow?

    ValueTask and `ValueTask<T>`: allocation-free synchronous completion, IValueTaskSource pooling, consumption rules and when Task is still the better choice.

    Senior Theory Tasks Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  10. What do the async and await keywords actually do? Explain what happens when execution reaches an await.

    The async modifier, the awaitable pattern, the IsCompleted fast path, continuation registration, context capture and valid async return types.

    Mid-Level Theory Tasks Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  11. What does the compiler generate for an async method? Explain the async state machine.

    IAsyncStateMachine, MoveNext, the state field, hoisted locals, the method builder, boxing on first suspension and the cost model of async in .NET 10.

    Senior Theory Tasks Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  12. What is a TaskScheduler, and what is the difference between TaskScheduler.Default and TaskScheduler.Current?

    TaskScheduler responsibilities, the default ThreadPool scheduler, Current versus Default pitfalls with StartNew and ContinueWith, FromCurrentSynchronizationContext and ConcurrentExclusiveSchedulerPair.

    Senior Theory Tasks Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  13. What are task continuations? Compare ContinueWith with await and explain the options that control how continuations run.

    ContinueWith, TaskContinuationOptions, synchronous versus asynchronous continuations, RunContinuationsAsynchronously, Unwrap and why await is usually better.

    Senior Theory Tasks Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  14. How are exceptions handled in tasks and async methods? What happens with Task.WhenAll, unobserved exceptions and async void?

    Exceptions stored in tasks, AggregateException versus await, WhenAll with several failures, cancellation status, UnobservedTaskException and async void crashes.

    Senior Debugging Tasks Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  15. What are the risks of fire-and-forget tasks in .NET, and how would you run background work safely in ASP.NET Core?

    Lost exceptions, disposed scoped services, lost work on shutdown, no backpressure; safe alternatives with BackgroundService, Channel of T and durable queues.

    Senior RealWorldScenario Tasks Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  16. How does the lock statement work in C#, and what changed with System.Threading.Lock in .NET 9 and C# 13?

    lock lowering to Monitor or Lock.EnterScope, choosing the lock object, re-entrancy, why you cannot await inside a lock, and lock scope design.

    Mid-Level Theory Synchronization Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  17. What does the Monitor class provide beyond the lock statement? Explain TryEnter, Wait and Pulse.

    Monitor.Enter/Exit, TryEnter with timeouts, Wait/Pulse/PulseAll condition signalling, thread affinity and the object header thin lock and sync block.

    Senior Theory Synchronization Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world
  18. What is a Mutex in .NET, how is it different from lock, and when would you use a named Mutex?

    Kernel mutex, cross-process named mutexes, Global and Local prefixes, AbandonedMutexException, thread affinity, cost and single-instance apps.

    Mid-Level Theory Synchronization Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  19. What is a Semaphore in .NET, and how does it differ from a Mutex?

    Counting semaphores, System.Threading.Semaphore as a kernel object, named semaphores and platform limits, no thread affinity, SemaphoreFullException and use cases.

    Mid-Level Theory Synchronization Β· πŸ”— 2 follow-ups Β· πŸ›  1 real-world
  20. What is SemaphoreSlim, and how do you use it as an async lock or to throttle concurrent async work?

    SemaphoreSlim internals, WaitAsync with timeouts and cancellation, async mutual exclusion, throttling HTTP calls, non-reentrancy and release discipline.

    Mid-Level Coding Synchronization Β· πŸ”— 3 follow-ups Β· πŸ›  1 real-world

🌐 Sangam's Webring

βͺ Previous 🏠 Main Next ⏩
πŸ’¬ Chat with me