C#编程:用Thread获取系统时间
private void button1_Click(object sender, EventArgs e)
{
System.Threading.Thread p_thread =
new System.Threading.Thread(
() =>
{
while (true)
{
this.Invoke(
(MethodInvoker)delegate()
{
this.Refresh();
Graphics p_graphics =
CreateGraphics();
p_graphics.DrawString(
"系统时间: " + DateTime.Now.ToString(
"yyyy年MM月dd日hh时mm分ss秒"
), new Font("宋体", 15),
Brushes.Blue,
new Point(10, 10));
});
System.Threading.Thread.Sleep(1000);
}
});
p_thread.IsBackground = true;
p_thread.Start();
}