PageRenderTime 61ms CodeModel.GetById 21ms RepoModel.GetById 0ms app.codeStats 0ms

/SignalR.Tests/CountDown.cs

https://github.com/kpmrafeeq/SignalR
C# | 40 lines | 35 code | 5 blank | 0 comment | 2 complexity | d507dd03531c9c89d629c66fac80f5b8 MD5 | raw file
Possible License(s): MIT
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. namespace SignalR.Tests
  7. {
  8. public class CountDown
  9. {
  10. private int _count;
  11. private ManualResetEventSlim _wh = new ManualResetEventSlim(false);
  12. public int Count
  13. {
  14. get
  15. {
  16. return _count;
  17. }
  18. }
  19. public CountDown(int count)
  20. {
  21. _count = count;
  22. }
  23. public void Dec()
  24. {
  25. if (Interlocked.Decrement(ref _count) == 0)
  26. {
  27. _wh.Set();
  28. }
  29. }
  30. public bool Wait(TimeSpan timeout)
  31. {
  32. return _wh.Wait(timeout);
  33. }
  34. }
  35. }