Câu hỏi phỏng vấn C#
Câu hỏi

Explain the difference between Task and Thread in .NET

Câu trả lời

Difference between Task and Thread in .NET

In .NET, both Task and Thread are used for asynchronous programming, but they have some key differences:

Thread

  • A Thread is a unit of execution within a process.
  • Threads are managed by the operating system's scheduler.
  • Threads can be created using the Thread class from the System.Threading namespace.
  • Threads are low-level constructs that provide direct access to the operating system's threading capabilities.
  • Threads require more system resources (memory, CPU time) compared to Tasks.
  • Threads can be used for both CPU-bound and I/O-bound operations.

Task

  • A Task is a higher-level abstraction over Threads.
  • Tasks are managed by the Task Parallel Library (TPL) in .NET.
  • Tasks can be created using the Task class ...
middle

middle

Gợi ý câu hỏi phỏng vấn

junior

Can this be used within a Static method?

senior

Can Multiple Inheritance implemented in C# ?

senior

IEnumerable vs List - What to Use? How do they work?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào