Parallel ForEach C# yog dab tsi?
Parallel ForEach C# yog dab tsi?

Video: Parallel ForEach C# yog dab tsi?

Video: Parallel ForEach C# yog dab tsi?
Video: PowerShell! Renaming Files 2024, Kaum ib hlis
Anonim

Foreach Loop nyob rau hauv C# sau raws li ib tug xov tooj thiab kev ua nyob rau hauv sequentially ib tug los ntawm ib tug. Foreach Loop yog qhov tseem ceeb ntawm C# thiab nws muaj los ntawm C# 1.0. Nws qhov kev ua tiav yog qeeb dua qhov Parallel.

Ua raws li qhov kev pom no, dab tsi yog qhov sib npaug ntawm C#?

Parallel . ForEach Txoj kev hauv C# Cov Parallel ForEach Txoj kev hauv C# muab ib thaum uas tig mus version ntawm tus qauv, sequential Foreach lub voj. Hauv tus qauv Foreach voj, txhua iteration txheej txheem ib yam khoom los ntawm kev sau thiab yuav ua txhua yam khoom ib los ntawm ib tug xwb. Rau thiab Parallel.

Kuj Paub, ua li cas koj tos rau parallel foreach kom tiav? Koj tsis tas yuav ua dab tsi tshwj xeeb, Parallel . Foreach () yuav tos mus txog rau thaum tag nrho nws cov hauj lwm ceg ua kom tiav . Los ntawm kev hu xov tooj koj tuaj yeem kho nws li ib nqe lus synchronous thiab piv txwv li qhwv nws hauv sim / ntes. Koj tsis xav tau nrog Parallel.

Xav txog qhov no, puas foreach khiav nyob rau hauv parallel?

A Parallel . ForEach loop ua haujlwm zoo li ib Parallel . Rau lub voj. Lub voj partitions qhov chaw sau thiab teem caij rau ua hauj lwm rau ntau threads raws li qhov system ib puag ncig.

Puas yog parallel foreach thread muaj kev nyab xeeb?

Xov Safety Txawm hais tias nws yooj yim heev los sau a parallel rau pem hauv ntej voj, koj tsis tuaj yeem yooj yim paste rau hauv cov cai los ntawm ib txwm ua ntej voj thiab cia siab tias nws yooj yim ua haujlwm. Qhov no txhais tau hais tias cov cai ua haujlwm tib yam txawm tias muaj ntau yam xov tab tom khiav tib lub sijhawm.

Pom zoo: