pho*_*ogl 4 c# parallel-processing for-loop ulong parallel.for
在 C# 中,有一个System.Threading.Tasks.Parallel.For(...)
which 的作用与循环相同for
,没有顺序,但在多个线程中。问题是,它只适用于long
和int
,我想使用ulong
。好的,我可以打字,但我在边框方面遇到了一些问题。
比方说,我想要一个从long.MaxValue-10
到 的循环long.MaxValue+10
(记住,我说的是ulong
)。我怎么做?
一个例子:
for (long i = long.MaxValue - 10; i < long.MaxValue; ++i)
{
Console.WriteLine(i);
}
//does the same as
System.Threading.Tasks.Parallel.For(long.MaxValue - 10, long.MaxValue, delegate(long i)
{
Console.WriteLine(i);
});
//except for the order, but theres no equivalent for
long max = long.MaxValue;
for (ulong i = (ulong)max - 10; i < (ulong)max + 10; ++i)
{
Console.WriteLine(i);
}
Run Code Online (Sandbox Code Playgroud)
您可以随时写信给 Microsoft,要求他们将 Parallel.For(ulong, ulong, Action<ulong>) 添加到下一版本的 .NET Framework 中。在那之前,你将不得不诉诸于这样的事情:
Parallel.For(-10L, 10L, x => { var index = long.MaxValue + (ulong) x; });
Run Code Online (Sandbox Code Playgroud)