How do I choose between Semaphore and SemaphoreSlim?

后端 未结 5 674
余生分开走
余生分开走 2020-12-04 18:41

Their public interfaces appear similar. The documentation states that the SemaphoreSlim is a lightweight alternative and doesn\'t use Windows Kernel semaphores. This resou

5条回答
  •  臣服心动
    2020-12-04 19:14

    Regarding "short times" controversy:

    At least SemaphoreSlim MSDN documentation states that

    The SemaphoreSlim class is the recommended semaphore for synchronization within a single app.

    in Remarks section. Same section also tells the main difference between Semaphore and SemaphoreSlim:

    The SemaphoreSlim is a lightweight alternative to the Semaphore class that doesn't use Windows kernel semaphores. Unlike the Semaphore class, the SemaphoreSlim class doesn’t support named system semaphores. You can use it as a local semaphore only.

提交回复
热议问题