标签:
运行环境:Microsoft Visio Studio 2015
控件说明:1.button(一键获取当前系统时间!) 2.TextBox(显示时间)
实现的效果如下:
完整源代码如下:
1 using System; 2 using System.Threading; 3 using System.Windows.Forms; 4 5 namespace EXP3_C53_GetTime_threading 6 { 7 public partial class Form1 : Form 8 { 9 public Form1() 10 { 11 InitializeComponent(); 12 } 13 bool flag = false; 14 15 public void showTime() 16 { 17 while (true) 18 { 19 DateTime dateTime = DateTime.Now; 20 textBox1.Text = "当前系统时间为:" + dateTime.ToString(); 21 Thread.Sleep(1000); 22 } 23 } 24 25 private void button1_Click(object sender, EventArgs e) 26 { 27 flag = true; 28 if (flag) 29 { 30 Thread P_thread = new Thread(new ThreadStart(showTime)); 31 P_thread.IsBackground = true; 32 P_thread.Start(); 33 } 34 } 35 36 } 37 }
注:本博客博文均为原创,转载请注明出处!
标签:
原文地址:http://www.cnblogs.com/CC2248/p/5410671.html