Stopwatch.Default.cs 1.4 KB

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