1
0

Stopwatch.Default.cs 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. // Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
  2. #if !NO_STOPWATCH
  3. using System.Diagnostics;
  4. namespace System.Reactive.Concurrency
  5. {
  6. //
  7. // WARNING: This code is kept *identically* in two places. One copy is kept in System.Reactive.Core for non-PLIB platforms.
  8. // Another copy is kept in System.Reactive.PlatformServices to enlighten the default lowest common denominator
  9. // behavior of Rx for PLIB when used on a more capable platform.
  10. //
  11. internal class DefaultStopwatch/*Impl*/ : IStopwatch
  12. {
  13. private readonly Stopwatch _sw;
  14. public DefaultStopwatch()
  15. {
  16. _sw = Stopwatch.StartNew();
  17. }
  18. public TimeSpan Elapsed
  19. {
  20. get { return _sw.Elapsed; }
  21. }
  22. }
  23. }
  24. #else
  25. namespace System.Reactive.Concurrency
  26. {
  27. // This class is only used on Silverlight in the browser. It mimicks !Stopwatch.HighResolution behavior and suffers from
  28. // use of absolute time. See work item 486045.
  29. internal class DefaultStopwatch : IStopwatch
  30. {
  31. private readonly DateTime _start;
  32. public DefaultStopwatch()
  33. {
  34. _start = DateTime.UtcNow;
  35. }
  36. public TimeSpan Elapsed
  37. {
  38. get { return DateTime.UtcNow - _start; }
  39. }
  40. }
  41. }
  42. #endif