Skip to content

Latest commit

 

History

History
9 lines (5 loc) · 577 Bytes

PH_S031.md

File metadata and controls

9 lines (5 loc) · 577 Bytes

PH_S031 - Monitor.Wait Inside Async Method or Task

Problem

Monitor.Wait(...) makes the current thread wait for a signal of another thread. Therefore, the waiting task depends on another, effectively blocking a thread of the TPL thread-pool. Although the TPL automatically increases the number of threads to meet a certain task throughput, it may negatively impact the overall application performance.

Solution

Tasks should be independent units of work. A good rule of thumb is to evaluate if the algorithm would work with a thread-pool with just a single thread.