【小5聊】C# for循环执行Task多线程,传参数不会重复的解决方法

【直接上代码】

List<int> list = new List<int>();
            for(int i = 0; i < taskCount;i++)
            {
                list.Add(i);
            }

            var tasks= list.Select(i => {

                return Task.Run(() => testData(new testModel() { startIndex = i * (100 / 5) }));
            });

            Task.WhenAll(tasks);

猜你喜欢

转载自blog.csdn.net/lmy_520/article/details/107681111
今日推荐