110,567
社区成员
发帖
与我相关
我的任务
分享
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;
using System.Threading;
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
Thread SetTitleThread = null;
delegate void SetTitle();
public Form1()
{
InitializeComponent();
SetTitleThread = new Thread(new ThreadStart(SetTitleSafely));
SetTitleThread.IsBackground = true;
SetTitleThread.Start();
}
void DoSetTitle()
{
this.Text = DateTime.Now.ToString("HH:mm:ss.fff");
}
void SetTitleSafely()
{
int StartTickCount = Environment.TickCount;
while (true)
{
if (this == null)
continue;
int EndTickCount = Environment.TickCount;
if (EndTickCount - StartTickCount > 1 * 1000) // 1秒
{
StartTickCount = EndTickCount;
SetTitle PSetTitle = new SetTitle(DoSetTitle);
if (this.InvokeRequired)
this.Invoke(PSetTitle, null);
else
this.Text = DateTime.Now.ToString("HH:mm:ss.fff");
}
}
}
}
}