gpt4 book ai didi

c# - 如何使用 C# 进行并行计算

转载 作者:行者123 更新时间:2023-11-30 15:32:29 24 4
gpt4 key购买 nike

我需要评估大约 10 万个结果,然后保存在一个列表中,因为这样我就可以在图表上表示出来。

但是只使用一个线程太长了,我决定使用多线程,但我对此一无所知。

这是我在单线程中使用的函数:

for(int i=min;i<max;i++)
{
list.Add(evaluate(expression, i));
}

我想用多线程做类似的事情。

最佳答案

您可能想查看 Task Parallel Library (TPL)Parallel Programming in .NET Framework 4

The purpose of the TPL is to make developers more productive by simplifying the process of adding parallelism and concurrency to applications. The TPL scales the degree of concurrency dynamically to most efficiently use all the processors that are available. In addition, the TPL handles the partitioning of the work, the scheduling of threads on the ThreadPool, cancellation support, state management, and other low-level details. By using TPL, you can maximize the performance of your code while focusing on the work that your program is designed to accomplish.

关于c# - 如何使用 C# 进行并行计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19034124/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com