C#实现实时时间显示

通过C#实现实时时间显示:


源代码如下:

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 ceshi4
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            new Thread(() =>
            {
                while (true)
                {
                    try
                    {
                        label1.BeginInvoke(new MethodInvoker(() =>
                            label1.Text = DateTime.Now.ToString()));
                    }
                    catch { }
                    Thread.Sleep(1000);
                }
            }) { IsBackground = true }.Start();


        }


        private void Form1_load(object sender, EventArgs e)
        {


        }
    }
}

你可能感兴趣的:(程序语言学习)