Ceci est un exemple de code de la page MSDN qui parle de Parallel.For. Je veux faire la même chose dans WinRT C#:Pour WinRT Metro Apps, quel est l'équivalent de Parallel.ForEach?
#region Sequential_Loop
static void MultiplyMatricesSequential(double[,] matA, double[,] matB, double[,] result)
{
int matACols = matA.GetLength(1);
int matBCols = matB.GetLength(1);
int matARows = matA.GetLength(0);
for (int i = 0; i < matARows; i++)
{
for (int j = 0; j < matBCols; j++)
{
for (int k = 0; k < matACols; k++)
{
result[i, j] += matA[i, k] * matB[k, j];
}
}
}
}
#endregion
#region Parallel_Loop
static void MultiplyMatricesParallel(double[,] matA, double[,] matB, double[,] result)
{
int matACols = matA.GetLength(1);
int matBCols = matB.GetLength(1);
int matARows = matA.GetLength(0);
// A basic matrix multiplication.
// Parallelize the outer loop to partition the source array by rows.
Parallel.For(0, matARows, i =>
{
for (int j = 0; j < matBCols; j++)
{
// Use a temporary to improve parallel performance.
double temp = 0;
for (int k = 0; k < matACols; k++)
{
temp += matA[i, k] * matB[k, j];
}
result[i, j] = temp;
}
}); // Parallel.For
}
#endregion
Quel est l'équivalent int C# pour WinRT Metro?
Dois-je créer un tableau de tâches et attendre l'achèvement du tableau?
A cette époque, il n'y a pas une méthode équivalente. L'extension du .NET Framework qui contient 'Parallel.ForEach' n'est pas contenue dans le profil Win RT .NET pour le moment. Si c'était le cas, votre code fonctionnerait. ** N'hésitez pas à en écrire un vous-même. ** –