A general class to manage threads

BenTam 1,561 Reputation points
2021-12-22T14:45:54.673+00:00

Dear All,

I am a beginner in C#. I want to create a class which can insert into any project for managing threads. However I don't know how to do it. Could anybody help me?

C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,266 questions
0 comments No comments
{count} votes

Accepted answer
  1. Michael Taylor 48,486 Reputation points
    2021-12-22T15:54:36.587+00:00

    .NET already has this as part of the thread pool it manages automatically for you. You don't need to create your own threads unless you have very specific needs such as having multiple long running threads (aka server threads) or similar. For short lived requests everything has switch to tasks as it is easier, cleaner and more efficient in many cases.

    Can you elaborate on why you need to create a library to manage threads? In general this extra layer isn't going to be useful outside perhaps the server side of a client-server application.


1 additional answer

Sort by: Most helpful
  1. Lex Li (Microsoft) 4,742 Reputation points Microsoft Employee
    2021-12-22T15:34:22.373+00:00

    In practice you never need that and you cannot easily write better code than a group of top professionals. Learn Task Parallel Library instead, https://learn.microsoft.com/en-us/dotnet/standard/parallel-programming/task-parallel-library-tpl