Comment faire pour déterminer quand la tâche est terminée

voici un exemple de code pour le démarrage de la tâche multiple

Task.Factory.StartNew(() =>
        {
            //foreach (KeyValuePair<string, string> entry in dicList)

            Parallel.ForEach(dicList,
                entry =>
                {

                    //create and add the Progress in UI thread
                    var ucProgress = (Progress)fpPanel.Invoke(createProgress, entry);

                    //execute ucProgress.Process(); in non-UI thread in parallel. 
                    //the .Process(); must update UI by using *Invoke
                    ucProgress.Process();

                    System.Threading.Thread.SpinWait(5000000);
                });
        });
.ContinueWith(task => 
  {
      //to handle exceptions use task.Exception member

      var progressBar = (ProgressBar)task.AsyncState;
      if (!task.IsCancelled)
      {
          //hide progress bar here and reset pb.Value = 0
      }
  }, 
  TaskScheduler.FromCurrentSynchronizationContext() //update UI from UI thread
  );

quand nous commençons à de multiples tâches à l'aide de Task.Factory.StartNew() ensuite, nous pouvons utiliser .ContinueWith() bloc pour déterminer le moment où chaque tâche de finition. je veux dire ContinueWith bloc feu une fois pour chaque réalisation de la tâche. donc, je veux juste savoir est-il un mécanisme de TPL de la bibliothèque. si je commence à 10 tâche à l'aide de Task.Factory.StartNew() alors, comment dois-je aviser après 10 tâche sera fini. veuillez donner un aperçu des exemples de code.

- Ils doivent être exécutés l'un après l'autre?

OriginalL'auteur Thomas | 2013-06-10