using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Threading;
namespace WindowsFormsApplication2
{
public partial class Form1 : Form
{
// private DateTime G_DateTime; //在Form中生成字段"G_DateTime"
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
var G_DateTime = DateTime.Now;
Thread P_th = new Thread(
() =>
{
while (true)
{
TimeSpan P_TimeSpan = DateTime.Now - G_DateTime;
Invoke(
(MethodInvoker)(() =>
{
label1.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();
}
private void statusStrip1_ItemClicked(object sender, ToolStripItemClickedEventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
}
}
}