diff --git a/SocketExample/TCPWindowV2.xaml b/SocketExample/TCPWindowV2.xaml index dbf8937..bbbe004 100644 --- a/SocketExample/TCPWindowV2.xaml +++ b/SocketExample/TCPWindowV2.xaml @@ -116,14 +116,22 @@ + - - - diff --git a/SocketExample/TCPWindowV2.xaml.cs b/SocketExample/TCPWindowV2.xaml.cs index 0b21c02..619e3cd 100644 --- a/SocketExample/TCPWindowV2.xaml.cs +++ b/SocketExample/TCPWindowV2.xaml.cs @@ -19,6 +19,7 @@ using System.Windows.Markup; using System.Windows.Media; using System.Windows.Media.Imaging; using System.Windows.Shapes; +using System.Windows.Threading; using System.Xml; using Google.Protobuf.WellKnownTypes; using K4os.Compression.LZ4.Streams.Abstractions; @@ -65,10 +66,13 @@ namespace SocketExample public static double? WindowHeight { get; set; } public static WindowState? OriginWindowState { get; set; } public static int? Buttonflag { get; set; } + private DispatcherTimer _timer; + public TCPWindowV2() { InitializeComponent(); EnsureFolderExists("日志文件夹"); + InitializeTimer(); this.Closing += TCPWindowV2_Closing; PanelContainer.ItemsSource = items; SaveWindowSettings(); @@ -521,6 +525,27 @@ namespace SocketExample OriginWindowState = this.WindowState; } + private void InitializeTimer() + { + _timer = new DispatcherTimer(); + _timer.Interval = TimeSpan.FromSeconds(1); // 每秒更新一次 + _timer.Tick += Timer_Tick; + _timer.Start(); + + // 立即显示时间 + UpdateClock(); + } + + private void Timer_Tick(object sender, EventArgs e) + { + UpdateClock(); + } + + private void UpdateClock() + { + DateTime now = DateTime.Now; + ClockText.Text = now.ToString("HH:mm:ss"); + } #endregion public class MyService : TcpService