0

it doesn't have to be high resolution, but I need to find Stopwatch in System.Diagnostics in Silverlight 5. In WP7, it is in Microsoft.Phone. (Sharing code across multiple platforms.)

I think it does exist, perhaps formerly in Microsoft.Device.dll.

Update Temporarily, it seems work to pull the Stopwatch.cs from the Mono library (which ultimately maps Stopwatch to Timespan).

Update2 Nope, that doesn't work, since it tries to call extern long GetTimestamp(); Probably this needs to be replaced with something SL can handle. Possibility http://blog.tiaan.com/link/2009/02/03/stopwatch-silverlight

tofutim
  • 22,664
  • 20
  • 87
  • 148

1 Answers1

1

WP7, Silverlight, and WPF all have a Stopwatch in System.Diagnostics;

However, I think the problem you might be facing is sharing a library between different frameworks. In order to share libraries across multiple frameworks you need a Announcement Portable Class Library or MSDN Portable Class Library

I really recommend though you create seperate class libraries for each framework and use something like the following in code:

#if WPF
// using statements for WPF
#elif SILVERLIGHT
// using statements for Silverlight
#elif WP7
// using statements for WP7
#endif

EDIT

Silverlight Stopwatch

MyKuLLSKI
  • 5,285
  • 3
  • 20
  • 39
  • Do you happen to know where to find the SILVERLIGHT stopwatch library? What should I reference? – tofutim Jan 30 '12 at 17:49
  • Its in System.Diagnostics http://msdn.microsoft.com/en-us/library/system.diagnostics.stopwatch%28v=vs.95%29.aspx AKA using System; – MyKuLLSKI Jan 30 '12 at 18:38
  • Hmm, I started a blank Silverlight 5 project and have System but it doesn't pick up. – tofutim Jan 30 '12 at 21:57
  • Browsing System.dll under System.Diagnostics, there is only "Debug", no stopwatch. In WP7, found under Microsoft.Phone.dll. – tofutim Jan 30 '12 at 22:00
  • It is very bad solution... since Environment.TickCount used in referenced code has less resolution than DateTime.Now.Ticks. It is 1 milliseconds in comparison to 100 nanoseconds. – Maxim Aug 20 '16 at 13:22