ConfigureAwait yog dab tsi?
ConfigureAwait yog dab tsi?

Video: ConfigureAwait yog dab tsi?

Video: ConfigureAwait yog dab tsi?
Video: BCS APSG 11th October 2012 Jon Skeet - Straighten Spaghetti Code with C# V5 2024, Tej zaum
Anonim

ConfigureAwait (tsis tseeb) suav nrog ib txoj haujlwm uas twb tau ua tiav los ntawm lub sijhawm nws tau tos (uas yog qhov ua tau zoo kawg), tom qab ntawd ConfigureAwait (tsis tseeb) yuav tsis muaj qab hau, raws li cov xov txuas ntxiv ua tiav cov txheej txheem tom qab qhov no thiab tseem nyob hauv tib lub ntsiab lus uas tau muaj yav tas los.

Tom qab ntawd, ib tug kuj yuav nug, dab tsi yog kev siv ConfigureAwait cuav?

ConfigureAwait ( cuav ) teeb tsa txoj haujlwm kom txuas ntxiv tom qab tos tsis tas yuav tsum tau khiav hauv cov ntsiab lus hu, yog li zam kom tsis txhob muaj kev cuam tshuam.

Ib sab saum toj, SynchronizationContext yog dab tsi? SynchronizationCov yog ib qho kev sawv cev ntawm ib puag ncig tam sim no uas peb cov cai tau khiav hauv. Qhov ntawd yog, nyob rau hauv ib qho asynchronous program, thaum peb delegate ib chav tsev ntawm kev ua hauj lwm rau lwm cov xov, peb ntes ib puag ncig tam sim no thiab khaws cia hauv ib qho piv txwv. SynchronizationCov thiab muab tso rau ntawm Task object.

Ua raws li qhov xav tau, kev siv ConfigureAwait yog dab tsi?

Siv ConfigureAwait (tsis tseeb) kom tsis txhob muaj kev tuag yog qhov kev coj ua txaus ntshai. Koj yuav tau siv ConfigureAwait (tsis tseeb) rau txhua tus tos hauv kev hloov pauv ntawm txhua txoj hauv kev hu ua los ntawm kev thaiv cov cai, suav nrog tag nrho cov lej thib peb thiab thib ob. Siv ConfigureAwait (tsis tseeb) kom tsis txhob muaj kev tuag yog qhov zoo tshaj plaws tsuas yog hack).

GetAwaiter yog dab tsi?

GetAwaiter () txoj kev, uas xa ib qho piv txwv uas muaj GetResult() txoj kev. Thaum siv rau qhov ua haujlwm tsis raug, GetResult() yuav tshaj tawm qhov kev zam tshwj xeeb (qhov no yog li cas "tos ua haujlwm;" tau txais nws tus cwj pwm). GetResult() vim tias nws khaws cov haujlwm tshwj tsis yog qhwv lawv hauv AggregateException.

Pom zoo: