Netduino home hardware projects downloads community

Jump to content


The Netduino forums have been replaced by new forums at community.wildernesslabs.co. This site has been preserved for archival purposes only and the ability to make new accounts or posts has been turned off.

Drasive

Member Since 29 Apr 2013
Offline Last Active Feb 15 2015 12:55 PM
-----

Posts I've Made

In Topic: System.Diagnostics.Stopwatch class

30 December 2013 - 09:35 PM

You are correct, my class had a pretty big bug in it, thanks for pointing that out. I updated it and it should work fine now.


In Topic: System.Diagnostics.Stopwatch class

03 June 2013 - 01:54 PM

I extended the class a little further:

using System;

namespace System.Diagnostics {
    
    public class Stopwatch {
        
        private long _ticksAtStart;
        private long _ticksNow;
        
        
        public bool IsRunning { get; private set; }
        
        public TimeSpan ElapsedDuration {
            get {
                return IsRunning ? new TimeSpan(0, 0, 0, 0, (int)((Microsoft.SPOT.Hardware.Utility.GetMachineTime().Ticks - _ticksAtStart) / TimeSpan.TicksPerMillisecond))
                                 : new TimeSpan(0, 0, 0, 0, (int)((_ticksNow - _ticksAtStart) / TimeSpan.TicksPerMillisecond));
            }
        }
        
        
        public void Start() {
            _ticksAtStart = Microsoft.SPOT.Hardware.Utility.GetMachineTime().Ticks;
            IsRunning = true;
        }
        
        public void Stop() {
            if (!IsRunning) {
                throw new InvalidOperationException();
            }
            
            _ticksNow = Microsoft.SPOT.Hardware.Utility.GetMachineTime().Ticks;
            IsRunning = false;
        }
        
        public void Resume() {
            if (IsRunning) {
                throw new InvalidOperationException();
            }
            
            _ticksAtStart = Microsoft.SPOT.Hardware.Utility.GetMachineTime().Ticks - (_ticksNow - _ticksAtStart);
            IsRunning = true;
        }
        
        public void Reset() {
            _ticksAtStart = 0;
            _ticksNow = 0;
            IsRunning = false;
        }
        
    }
    
}


home    hardware    projects    downloads    community    where to buy    contact Copyright © 2016 Wilderness Labs Inc.  |  Legal   |   CC BY-SA
This webpage is licensed under a Creative Commons Attribution-ShareAlike License.