What should I do with the thread when this is done? leave it or interrupt?

I am creating regular threads in an application asp.net. After the thread is done, what should I do? leave it (it will return to the thread pool) or interrupt it.

Thread thread = new Thread(new ThreadStart(work));
+3
source share
3 answers

Leave it. It makes no sense to create a meaningless exception.

+3
source

Recall that an interface IDisposableexists specifically for a scenario in which one share is to be released. (Of course, this was applied in other contexts, but this is the situation because of which it was originally intended.)

, Thread IDisposable, (), - , GC.

+2

using thread pools in c #

   [STAThread]
    public static void Main(string[] args)
    {
      foreach(var  fileNamePath in DirectoryFiles)
      {
         ThreadPool.QueueUserWorkItem(ThreadPoolCallback, fileNamePath);
      }
    }

  public void ThreadPoolCallback(object threadContext)
  {
       //do something 
  }

ThreadPool in .NET handles everything else.

+1
source

Source: https://habr.com/ru/post/1785127/


All Articles