现在正做一个 C/S 的自动更新, 需要接收 用户设定的时间 访问服务器。 这一步怎么来实现呢? 大虾给与帮助。。

解决方案 »

  1.   

    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Text;
    using System.Windows.Forms;namespace WindowsApplication1
    {    public class DEMO : Form
        {
            /// <summary>
            /// 必需的设计器变量。
            /// </summary>
            private System.ComponentModel.IContainer components = null;        /// <summary>
            /// 清理所有正在使用的资源。
            /// </summary>
            /// <param name="disposing">如果应释放托管资源,为 true;否则为 false。</param>
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }        #region Windows 窗体设计器生成的代码        /// <summary>使用代码编辑器修改此方法的内容。
            /// </summary>
            private void InitializeComponent()
            {
                this.components = new System.ComponentModel.Container();
                this.timer1 = new System.Windows.Forms.Timer(this.components);
                this.label1 = new System.Windows.Forms.Label();
                this.dateTimePicker1 = new System.Windows.Forms.DateTimePicker();
                this.SuspendLayout();
                // 
                // timer1
                // 
                this.timer1.Enabled = true;
                this.timer1.Interval = 1000;
                this.timer1.Tick += new System.EventHandler(this.timer1_Tick);
                // 
                // label1
                // 
                this.label1.AutoSize = true;
                this.label1.Location = new System.Drawing.Point(0, 5);
                this.label1.Name = "label1";
                this.label1.Size = new System.Drawing.Size(59, 12);
                this.label1.TabIndex = 0;
                this.label1.Text = "更新日期:";
                // 
                // dateTimePicker1
                // 
                this.dateTimePicker1.CustomFormat = "yyyy年MM月dd日 HH:mm:ss";
                this.dateTimePicker1.Format = System.Windows.Forms.DateTimePickerFormat.Custom;
                this.dateTimePicker1.Location = new System.Drawing.Point(62, 0);
                this.dateTimePicker1.Name = "dateTimePicker1";
                this.dateTimePicker1.Size = new System.Drawing.Size(160, 21);
                this.dateTimePicker1.TabIndex = 1;
                this.dateTimePicker1.Value = new System.DateTime(2008, 3, 7, 12, 0, 0, 0);
                // 
                // Form1
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(222, 21);
                this.Controls.Add(this.dateTimePicker1);
                this.Controls.Add(this.label1);
                this.Name = "Form1";
                this.Text = "示例.";
                this.ResumeLayout(false);
                this.PerformLayout();        }        #endregion        private System.Windows.Forms.Timer timer1;
            private System.Windows.Forms.Label label1;
            private System.Windows.Forms.DateTimePicker dateTimePicker1;        public DEMO()
            {
                InitializeComponent();
            }        private void timer1_Tick(object sender, EventArgs e)
            {
                if (DateTime.Now.CompareTo(this.dateTimePicker1.Value) >= 0)
                {
                    MessageBox.Show("执行自动更新");
                }
            }
        }
    }
      

  2.   

    实际上你可将 Timer.Interval 的值设大一点(节省资源)...