There are several environment dependencies here:
- What version of .NET are you using?
- Which user interface do you use - desktop (WPF / WinForms) or ASP.NET?
Suppose this is .NET 4.0 or higher and a desktop application.
Reading sensors
In a WPF or WinForms application, I would use a single BackgroundWorker to read data from sensors. 500 views per second is trivial - even 500.00 is usually trivial. The BackgroundWorker type is specifically designed for interacting with desktop applications, for example, for outputting results to the user interface without worrying about thread interactions.
Computation processing
Then you need to handle the “complex” calculations. It depends on how durable these calculations are. If we assume that they are short-lived (say, less than 1 second each), then I think using TaskScheduler and the standard ThreadPool will be fine. This way you create a Task for each calculation, and then let the TaskScheduler take care of the distribution of tasks for the threads.
TaskScheduler's task is to balance the load by queuing tasks for heavier threads and managing ThreadPool to better balance the workload and the number of cores on the machine. You can even override the default TaskScheduler to schedule tasks in any way.
ThreadPool is the FIFO queue of work items that need to be processed. In .NET 4.0, ThreadPool has improved performance by creating a work queue in the thread-safe ConcurrentQueue collection .
Performance and efficiency of the measurement task
You can use the PerformanceCounter to measure both CPU and memory usage . This will give you an idea of whether the cores and memory are being used efficiently. Task throughput is simply measured by examining the processing speed of the tasks and presenting the results.
Please note: I have not included any code here, as I assume that you want to deal with the details of your professor's implementation :-)
source share