计时器—计应192(西)-第六组-杨署魁

属性:

  Elapsed       获取当前实例测量得出的总运行时间。
  ElapsedMilliseconds 获取当前实例测量得出的总运行时间(以毫秒为单位)。
  ElapsedTicks     获取当前实例测量得出的总运行时间(用计时器计时周期表示)。
  IsRunning      获取一个指示 Stopwatch 计时器是否在运行的值。

方法:

  GetTimestamp   获取计时器机制中的当前最小时间单位数。
  Reset        停止时间间隔测量,并将运行时间重置为零。
  Restart       停止时间间隔测量,将运行时间重置为零,然后开始测量运行时间。
  Start        开始或继续测量某个时间间隔的运行时间。
  StartNew      对新的 Stopwatch 实例进行初始化,将运行时间属性设置为零,然后开始测量运行时间。
  Stop        停止测量某个时间间隔的运行时间。

代码:using System;

 using System.Collections.Generic;
 using System.ComponentModel;
using System.Data;
 using System.Drawing;
 using System.Linq;
 using System.Text;
using System.Windows.Forms;

 namespace TimerDemo
 {
 public partial class FrmMain : Form
 {
 //定义全局变量
 public int currentCount = 0;
 public FrmMain()
 {
InitializeComponent();
 }
 
 private void FrmMain_Load(object sender, EventArgs e)
 {
//设置Timer控件可用
this.timer.Enabled = true;
 //设置时间间隔(毫秒为单位)
 this.timer.Interval = 1000;
 }

 private void timer_Tick(object sender, EventArgs e)
 {
 currentCount += 1;
 this.txt_Count.Text = currentCount.ToString().Trim();
 }

 private void btn_Start_Click(object sender, EventArgs e)
{
 //开始计时
 this.timer.Start();
 }

 private void btn_Stop_Click(object sender, EventArgs e)
{
 //停止计时
 this.timer.Stop();
}
}
 }

2、System.Timers.Timer

设计界面:

后台代码:

 using System;
 using System.Collections.Generic;
 using System.ComponentModel;
 using System.Data;
 using System.Drawing;
 using System.Linq;
 using System.Text;
 using System.Windows.Forms;

 namespace TimersTimer
 {
 public partial class FrmMain : Form
 {
//定义全局变量
 public int currentCount = 0;
//定义Timer类
 System.Timers.Timer timer;
 //定义委托
 public delegate void SetControlValue(string value);

 public FrmMain()
 {
 InitializeComponent();
 }

 private void Form1_Load(object sender, EventArgs e)
 {
 InitTimer();
 }

/// <summary>
 /// 初始化Timer控件
/// </summary>
 private void InitTimer()
 {
 //设置定时间隔(毫秒为单位)
 int interval = 1000;
 timer = new System.Timers.Timer(interval);
 //设置执行一次(false)还是一直执行(true)
 timer.AutoReset = true;
 //设置是否执行System.Timers.Timer.Elapsed事件
 timer.Enabled = true;
//绑定Elapsed事件
timer.Elapsed += new System.Timers.ElapsedEventHandler(TimerUp);
 }

 /// <summary>
/// Timer类执行定时到点事件
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void TimerUp(object sender, System.Timers.ElapsedEventArgs e)
{
 try
 {
 currentCount += 1;
 this.Invoke(new SetControlValue(SetTextBoxText),currentCount.ToString());
}
 catch (Exception ex)
 {
 MessageBox.Show("执行定时到点事件失败:" + ex.Message);
 }
 }

/// <summary>
 /// 设置文本框的值
 /// </summary>
 /// <param name="strValue"></param>
 private void SetTextBoxText(string strValue)
 {
 this.txt_Count.Text = this.currentCount.ToString().Trim();
 }

 private void btn_Start_Click(object sender, EventArgs e)
 {
 timer.Start();
 }

 private void btn_Stop_Click(object sender, EventArgs e)
 {
timer.Stop();
82 }
 }
 }

3、System.Threading.Timer

设计界面:

后台代码:


1 using System;
2 using System.Collections.Generic;
3 using System.ComponentModel;
4 using System.Data;
5 using System.Drawing;
6 using System.Linq;
7 using System.Text;
8 using System.Windows.Forms;
9 using System.Threading;
10
11 namespace Threading.Timer
12 {
13 public partial class FrmMain : Form
14 {
15 //定义全局变量
16 public int currentCount = 0;
17 //定义Timer类
18 System.Threading.Timer threadTimer;
19 //定义委托
20 public delegate void SetControlValue(object value);
21
22 public FrmMain()
23 {
24 InitializeComponent();
25 }
26
27 private void FrmMain_Load(object sender, EventArgs e)
28 {
29 InitTimer();
30 }
31
32 /// <summary>
33 /// 初始化Timer类
34 /// </summary>
35 private void InitTimer()
36 {
37 threadTimer = new System.Threading.Timer(new TimerCallback(TimerUp), null, Timeout.Infinite, 1000);
38 }
39
40 /// <summary>
41 /// 定时到点执行的事件
42 /// </summary>
43 /// <param name="value"></param>
44 private void TimerUp(object value)
45 {
46 currentCount += 1;
47 this.Invoke(new SetControlValue(SetTextBoxValue), currentCount);
48 }
49
50 /// <summary>
51 /// 给文本框赋值
52 /// </summary>
53 /// <param name="value"></param>
54 private void SetTextBoxValue(object value)
55 {
56 this.txt_Count.Text = value.ToString();
57 }
58
59 /// <summary>
60 /// 开始
61 /// </summary>
62 /// <param name="sender"></param>
63 /// <param name="e"></param>
64 private void btn_Start_Click(object sender, EventArgs e)
65 {
66 //立即开始计时,时间间隔1000毫秒
67 threadTimer.Change(0, 1000);
68 }
69
70 /// <summary>
71 /// 停止
72 /// </summary>
73 /// <param name="sender"></param>
74 /// <param name="e"></param>
75 private void btn_Stop_Click(object sender, EventArgs e)
76 {
77 //停止计时
78 threadTimer.Change(Timeout.Infinite, 1000);
79 }
80 }
81 }

 

PSP 各个阶段

 预估时间

(分钟)

实际记录

(分钟)

计划:明确需求和其他因素,估计以下的各个任务需要多少时间 

 

 

开发(包括下面8项子任务)

 

 

. 需求分析(包括学习新技术、新工具的时间)

 120 

 100

. 生成设计文档(整体框架的设计,各模块的接口,用时序图,快速原型等方法)

 120

 130

. 设计复审 (和同事审核设计文档,或者自己复审)

 60

 60

.代码规范(为目前的开发制定或选择合适的规范)

 60

 50

.具体设计(用伪代码,流程图等方法来设计具体模块)

 120

 100

.具体编码

 150

 130

.代码复审

 60

 30

.测试(自我测试,修改代码,提交修改)

 30

 20

总共花费的时间(分钟)

 720

 620
posted @ 2021-04-11 17:19  计应192西六组  阅读(60)  评论(0编辑  收藏  举报