请教到设定的时间就自动执行方法,应该如何实现?
例如,我添加一个广播,设定了一个时间,到时间就执行一个方法来广播
需要添加好多个广播
那么我应该怎么实现呢??谢谢
------解决方案--------------------我现在用的:
c#怎么做一个定时运行程序!!!
用timer控件,检测时间后触发事件
timer控件
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
namespace NoticePad
{
/// <summary>
/// 定时提醒的小工具。
/// </summary>
public class Form1 : System.Windows.Forms.Form
{
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Label label2;
private System.Windows.Forms.TextBox textBox1;
private System.Windows.Forms.Timer timer1;
private System.Windows.Forms.NumericUpDown ndHour;
private System.Windows.Forms.NumericUpDown ndMinute;
private System.Windows.Forms.Button btn_OK;
private System.ComponentModel.IContainer components;
public Form1()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent();
//
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
}
/// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if (components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
}
#region Windows Form Designer generated code
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.ndHour = new System.Windows.Forms.NumericUpDown();
this.ndMinute = new System.Windows.Forms.NumericUpDown();
this.label1 = new System.Windows.Forms.Label();
this.label2 = new System.Windows.Forms.Label();
this.textBox1 = new System.Windows.Forms.TextBox();
this.btn_OK = new System.Windows.Forms.Button();
this.timer1 = new System.Windows.Forms.Timer(this.components);
((
System.ComponentModel.ISupportInitialize)(this.ndHour)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.ndMinute)).BeginInit();
this.SuspendLayout();
//
// ndHour
//
this.ndHour.Location = new System.Drawing.Point(6, 6);
this.ndHour.Maximum = new System.Decimal(new int[] {
23,
0,
0,
0});
this.ndHour.Name = "ndHour ";
this.ndHour.Size = new System.Drawing.Size(36, 21);
this.ndHour.TabIndex = 0;
//
// ndMinute
//
this.ndMinute.Location = new System.Drawing.Point(84, 6);
this.ndMinute.Maximum = new System.Decimal(new int[] {
59,
0,
0,
0});
this.ndMinute.Name = "ndMinute ";
this.ndMinute.Size = new System.Drawing.Size(36, 21);
this.ndMinute.TabIndex = 1;
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(48, 12);