通過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)
{
}
}
}