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

senior

When to use ArrayList over array[] in C#?

expert

What is jagged array in C# and when to prefer jagged arrays over multi-dimensional arrays?

expert

Could you explain the difference between destructor , dispose and finalize method?

Bình luận

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

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