| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132 | //时间:20200611//作者:郝爽//功能:测量状态using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace MeasureThread{    //测试结果    public enum ThreadState    {        Ready,     //就绪        InProcess, //进行中        Waiting,   //等待,半自动化测试过程的状态        Failed,    //失败        Success    //成功    }    //计算时间类型    public enum THREAD_TIME_TYPE    {        START = 1,        STOPPED = 2,    }    public class ThreadStatus    {        //线程状态        private ThreadState m_threadState;        public ThreadState STATE        {            get { return this.m_threadState; }            set { this.m_threadState = value; }        }        //线程开始的时间        private DateTime m_startTime;        public DateTime StartTime        {            get { return this.m_startTime; }            set { this.m_startTime = value; }        }        //线程结束的时间        private DateTime m_endTime;        public DateTime EndTime        {            get { return this.m_endTime; }            set { this.m_endTime = value; }        }        //线程使用的时间        private TimeSpan m_UsedTime;        public TimeSpan UsedTime        {            get { return this.m_UsedTime; }            set { this.m_UsedTime = value; }        }        //线程当前开始的时间        private DateTime m_CurrentStartTime;        public DateTime CurrentStartTime        {            get { return this.m_CurrentStartTime; }            set { this.m_CurrentStartTime = value; }        }        //构造函数        public ThreadStatus()        {            Init();        }        public void Init()        {            m_threadState = ThreadState.Ready;            m_startTime = new DateTime();            m_endTime = new DateTime();            m_CurrentStartTime = new DateTime();            m_UsedTime = m_endTime - m_startTime;        }        // 计算时间        public bool ComputeTime(THREAD_TIME_TYPE a_nType)        {            if (a_nType == THREAD_TIME_TYPE.START)            {                if (m_startTime == new DateTime())                {                    m_startTime = DateTime.Now;                    m_CurrentStartTime = m_startTime;                }                else                {                    m_CurrentStartTime = DateTime.Now;                }                m_endTime = DateTime.Now;            }            else if (a_nType == THREAD_TIME_TYPE.STOPPED)            {                // set current time as end time                m_endTime = DateTime.Now;                // compute used time                TimeSpan timeUsed = new TimeSpan();                if (m_CurrentStartTime == m_startTime)                {                    // first compute time                    timeUsed = m_endTime - m_startTime;                }                else                {                    // not the first compute time                    timeUsed = m_UsedTime + ( m_endTime - m_CurrentStartTime);                }                m_UsedTime = timeUsed;            }            else            {                return false;            }            return true;        }    }}
 |