C# Winform小程序:局域网设置NTP服务器、实现时间同步 |
您所在的位置:网站首页 › 电脑时钟程序 › C# Winform小程序:局域网设置NTP服务器、实现时间同步 |
设置NTP服务器:
NTP是网络时间协议(Network Time Protocol),它是用来同步网络中各个计算机的时间的协议。 局域网不能连接Internet,可以设置一台计算机为NTP服务器。 依次点击:开始---运行---regedit,进入注册表;依次展开:HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\W32Time\TimeProviders\NtpServer,在NtpServer项右侧键值Enablied,默认值0改为1,1为启动NTP服务器;全局变量: //Timer System.Timers.Timer timer = new System.Timers.Timer(); //IP private string ipAddress; //时间间隔 private int timeInterval; //创建bat文件路径,如果存在,直接覆盖 private string filePath = System.Environment.CurrentDirectory + @"\timesync.bat";页面Load方法: private void FrmMain_Load(object sender,EventArgs e) { //运行标志隐藏 picRun.Visible = false; }Run/Abort按钮点击事件: private void btnRunAbort_Click(object sender,EventArgs e) { //IP ipAddress = txtIP.Text.Trim(); //Time Interval timeInterval = Convert.ToInt32(txtTimeInterval.Text); if (btnRunAbort.Text.Equals("开始同步")) { this.RunTimer(); } else if (btnRunAbort.Text.Equals("停止同步")) { //定时器停止 timer.Stop(); timer = new System.Timers.Timer(); MessageBox.Show("停止同步成功","提示"); //运行标志隐藏 picRun.Visible = false; btnRunAbort.Text = "开始同步"; } }引用网址:https://www.cnblogs.com/benpaodejiandan/p/8385448.html |
今日新闻 |
推荐新闻 |
CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3 |