效果图:

代码:

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;
using System.Threading;

namespace Example66
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private DateTime G_DateTime;

private void Form1_Load(object sender, EventArgs e)
{
G_DateTime = DateTime.Now; //获取当前时间变量
Thread P_th = new Thread(
() => //使用lanmda表达式
{
while (true) //无线循环
{
TimeSpan P_timespan = DateTime.Now - G_DateTime; //得到时间差
Invoke( //调用窗体线程
(MethodInvoker)(() =>
{
toolStripStatusLabel1.Text = //
string.Format(
"系统已经运行:{0}天{1}小时{2}分{3}秒",
P_timespan.Days, P_timespan.Hours,
P_timespan.Minutes, P_timespan.Seconds);
}));
Thread.Sleep(1000);
}
});
P_th.IsBackground = true; //设置为 后台线程
P_th.Start();
}
}
}

posted on 2011-10-26 23:12  C#_初学者  阅读(282)  评论(0编辑  收藏  举报