[. NET] Quick notes on Objective C # (4)-use the framework,

Source: Internet
Author: User

[. NET] Quick notes on Objective C # (4)-use the framework,
Quick notes for Objective C # (4)-use the framework

Var list = new List <int> (); var query = list. where (x => x <150 ). select (x => x. toString (); // query var queryParallel = list in parallel. asParallel (). where (x => x <150 ). select (x => x. toString ());

 

36. Understanding PLINQ in I/O intensive scenarios
Var urls = new List <string> (); foreach (var url in urls) {var result = new WebClient (). downloadData (url); // send a synchronous Web request and wait for receiving data. This mainly wastes time waiting for the Console. writeLine (result);} // use the Parallel processing model Parallel. forEach (urls, url => {var result = new WebClient (). downloadData (url); Console. writeLine (result) ;}); // use PLINQ var results = from url in urls. asParallel () select new WebClient (). downloadData (url); results. forAll (Console. write );

1. The execution method of PLINQ is different from that of Parallel. ForEach () in the Parallel job library. PLINQ uses a fixed number of threads, while Parallel. ForEach () adjusts the number of threads to increase throughput.

2. For those operations that mix I/O-intensive and CPU-intensive, Parallel. ForEach () is more suitable. Parallel. ForEach () dynamically adjusts the number of threads based on the current load. When many threads are blocked due to waiting for I/O operations, Parallel. ForEach () will create more threads to increase throughput. When many threads are working, Parallel. ForEach () also limits the number of active threads and reduces the cost of context switching.

3. for programs that need to access other computers and wait for Remote Response, the parallel task library and PLINQ play an important role.

 

37. Pay attention to exceptions in Parallel Algorithms

1. Exceptions in background threads increase complexity in different aspects. An exception cannot pass through the thread boundary to keep the call stack. When the exception is passed to the method of the start thread, the thread will stop. The call thread cannot capture this error and cannot process it accordingly.

2. Once the background thread throws an exception, other background operations will also stop. It is best not to throw exceptions in parallel algorithms. However, other unexpected exceptions may also occur.

 

This series

Quick notes in Objective C # (1)-C # language habits

Quick notes for Objective C # (2)-. NET resource hosting

Quick notes in Objective C # (III)-use C # To express design

Quick notes for Objective C # (4)-use the framework

 

 

[Blogger] Anti-Bot

Http://www.cnblogs.com/liqingwen/p/6797709.html.

[GitHub] https://github.com/liqingwen2015/XMind can download XMind

[Reference] Objective C #

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.