Multi threading which would be the best to use? (Threadpool or threads)

前端 未结 7 1475
醉梦人生
醉梦人生 2021-01-07 02:52

Hopefully this is a better question than my previous. I have a .exe which I will be passing different parameters (file paths) to which it will then take in and parse. So I w

相关标签:
7条回答
  • 2021-01-07 03:19

    To answer your revised question, you want processes. You just need to create the correct number of processes running the exe. Don't worry about forcing them onto specific cores. Windows will do that automatically.

    How to do this:

    You want to determine the number of cores on the machine. You may simply know it, and hardcode it, or you might want to use something like System.Environment.ProcessorCount.

    Create a List<Process> object.

    Then you want to start that many processes using System.Diagnostics.Process.Start. The return value will be a process object, which you will want to add to the List.

    Now repeat the following until you are finished:

    Call Thread.Sleep to wait for a while. Perhaps a minute or so.

    Loop through each Process in the list but be sure to use a for loop rather than a foreach loop. For each process, call Refresh() then check the 'HasExited' property of each process, and if it is true, create a new process using Process.Start, and replace the exited process in the list with the newly created one.

    0 讨论(0)
提交回复
热议问题