Description
The Sandbox.Utility.Parallel.For
method executes a parallel loop over a range of integers, from fromInclusive
to toExclusive
. It allows for concurrent execution of the specified body
action on each integer in the range, potentially improving performance by utilizing multiple threads.
Usage
To use the For
method, provide the starting index fromInclusive
, the ending index toExclusive
, and an Action<int>
delegate body
that defines the operation to perform on each index. The method returns a bool
indicating whether the loop completed successfully.
Example
// Example usage of Sandbox.Utility.Parallel.For
bool result = Sandbox.Utility.Parallel.For(0, 100, i =>
{
// Perform some operation on each index i
ProcessData(i);
});
if (result)
{
// The loop completed successfully
Console.WriteLine("Parallel loop completed successfully.");
}
else
{
// The loop was terminated prematurely
Console.WriteLine("Parallel loop was terminated.");
}
void ProcessData(int index)
{
// Example operation
Console.WriteLine($"Processing index: {index}");
}