gpt4 book ai didi

c# - 线程问题-产生多个线程的最佳方法

转载 作者:太空宇宙 更新时间:2023-11-03 17:34:35 25 4
gpt4 key购买 nike

我创建了一个方法,我们称它为MemoryStressTest()。我想从另一个方法中调用它,让我们将其称为InitiateMemoryStressTest()。我希望InitiateMemoryStressTest()方法通过不同的线程调用MemoryStressTest()的多个实例。线程不需要彼此了解,也不会相互依赖。我正在使用.NET4。什么是最好的方法?

最佳答案

尽可能简单:

        int threadCount = 100;
for (int i = 0; i < threadCount; i++)
{
(new Thread(() => MemoryStressTest())).Start();
}

关于c# - 线程问题-产生多个线程的最佳方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5912418/

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