Parallel LINQ (PLINQ)

Parallel LINQ is a version of LINQ that executes queries in parallel on multi-core CPUs. It contains the full set of standard LINQ query operators plus some additional operators for parallel operations. It is highly advisable that you use this for long-running tasks, although incorrect use may slow down the performance of your app. Parallel LINQ operates on collections such as List, List<T>, IEnumerable, IEnumerable<T> and so on. Under the hood, it splits the list into segments and runs each segment on a different processor of the CPU.

Here is a modified version of the previous example, with Parallel.ForEach instead of the PLINQ operation:

static void Main(string[] args) 
{ 
  List<Document> docs = GetUserDocuments(); 
 
  var query = from doc in docs.AsParallel() 
  select ManageDocument(doc); 
} 
 
private static Document ManageDocument(Document doc) 
{ 
  Thread.Sleep(1000); 
  return doc; 
} 
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
52.14.134.113