为什么不能同时存在多个Timer? 多个TIMER是没有问题的,可能是你TIMER内的代码运算量比较大,可以试试在方法里面加上若干个DOEVENTS()如果有多个TIMER,应该用线程效率更高一点,TIMER的效率不好 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 可以的。我做了个DEMOusing System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;namespace Sample{ /// <summary> /// frmMultiTimer 的摘要说明。 /// </summary> public class frmMultiTimer : System.Windows.Forms.Form { private System.Windows.Forms.Label lblTimer1; private System.Windows.Forms.Label lblTimer2; private System.ComponentModel.IContainer components = null; public frmMultiTimer() { // // Windows 窗体设计器支持所必需的 // InitializeComponent(); // // TODO: 在 InitializeComponent 调用后添加任何构造函数代码 // } /// <summary> /// 清理所有正在使用的资源。 /// </summary> protected override void Dispose( bool disposing ) { if( disposing ) { if(components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows 窗体设计器生成的代码 /// <summary> /// 设计器支持所需的方法 - 不要使用代码编辑器修改 /// 此方法的内容。 /// </summary> private void InitializeComponent() { this.lblTimer1 = new System.Windows.Forms.Label(); this.lblTimer2 = new System.Windows.Forms.Label(); this.SuspendLayout(); // // lblTimer1 // this.lblTimer1.Location = new System.Drawing.Point(32, 24); this.lblTimer1.Name = "lblTimer1"; this.lblTimer1.TabIndex = 0; this.lblTimer1.Text = "0"; this.lblTimer1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // lblTimer2 // this.lblTimer2.Location = new System.Drawing.Point(32, 72); this.lblTimer2.Name = "lblTimer2"; this.lblTimer2.TabIndex = 1; this.lblTimer2.Text = "0"; this.lblTimer2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; // // frmMultiTimer // this.AutoScaleBaseSize = new System.Drawing.Size(6, 14); this.ClientSize = new System.Drawing.Size(292, 149); this.Controls.Add(this.lblTimer2); this.Controls.Add(this.lblTimer1); this.Name = "frmMultiTimer"; this.Text = "frmMultiTimer"; this.Load += new System.EventHandler(this.frmMultiTimer_Load); this.ResumeLayout(false); } #endregion private Timer pTimer1 = new Timer(); private Timer pTimer2 = new Timer(); private void frmMultiTimer_Load(object sender, System.EventArgs e) { pTimer1.Interval = 200; pTimer1.Tick += new EventHandler(pTimer_Tick); pTimer1.Enabled = true; pTimer2.Interval = 400; pTimer2.Tick += new EventHandler(pTimer_Tick); pTimer2.Enabled = true; } private void pTimer_Tick(object sender, System.EventArgs e) { if(((Timer)sender == pTimer1)) { lblTimer1.Text = Convert.ToString(Convert.ToInt32(lblTimer1.Text) + 1); } else { lblTimer2.Text = Convert.ToString(Convert.ToInt32(lblTimer2.Text) + 1); } } }} 可以同时使用,我试过的。肯定是你的程序不对。不要在每个Timer_tick里干很多事情 用Visual Studio 编写代码时的使用技巧????????? 新手关于ADO.NET的问题 C#2005 父窗体与子窗体的问题 关于DBNull的两个问题,有人知道吗?????!!!!! 怎么样能删除 new 时的静态变量? 怎样将xml数据源邦定到DataGrid? 添加web服务的时候(Add Web Reference)出错 随机函数 怎样在邮件地址错误时弹出信息窗口? 关于WEB端用户控件重用的问题,个人觉得很难!!! 界面组件 哪里能 下载 nunit C#测试工具??各位帮帮忙:)
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;namespace Sample
{
/// <summary>
/// frmMultiTimer 的摘要说明。
/// </summary>
public class frmMultiTimer : System.Windows.Forms.Form
{
private System.Windows.Forms.Label lblTimer1;
private System.Windows.Forms.Label lblTimer2;
private System.ComponentModel.IContainer components = null; public frmMultiTimer()
{
//
// Windows 窗体设计器支持所必需的
//
InitializeComponent(); //
// TODO: 在 InitializeComponent 调用后添加任何构造函数代码
//
} /// <summary>
/// 清理所有正在使用的资源。
/// </summary>
protected override void Dispose( bool disposing )
{
if( disposing )
{
if(components != null)
{
components.Dispose();
}
}
base.Dispose( disposing );
} #region Windows 窗体设计器生成的代码
/// <summary>
/// 设计器支持所需的方法 - 不要使用代码编辑器修改
/// 此方法的内容。
/// </summary>
private void InitializeComponent()
{
this.lblTimer1 = new System.Windows.Forms.Label();
this.lblTimer2 = new System.Windows.Forms.Label();
this.SuspendLayout();
//
// lblTimer1
//
this.lblTimer1.Location = new System.Drawing.Point(32, 24);
this.lblTimer1.Name = "lblTimer1";
this.lblTimer1.TabIndex = 0;
this.lblTimer1.Text = "0";
this.lblTimer1.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// lblTimer2
//
this.lblTimer2.Location = new System.Drawing.Point(32, 72);
this.lblTimer2.Name = "lblTimer2";
this.lblTimer2.TabIndex = 1;
this.lblTimer2.Text = "0";
this.lblTimer2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// frmMultiTimer
//
this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
this.ClientSize = new System.Drawing.Size(292, 149);
this.Controls.Add(this.lblTimer2);
this.Controls.Add(this.lblTimer1);
this.Name = "frmMultiTimer";
this.Text = "frmMultiTimer";
this.Load += new System.EventHandler(this.frmMultiTimer_Load);
this.ResumeLayout(false); }
#endregion
private Timer pTimer1 = new Timer();
private Timer pTimer2 = new Timer();
private void frmMultiTimer_Load(object sender, System.EventArgs e)
{
pTimer1.Interval = 200;
pTimer1.Tick += new EventHandler(pTimer_Tick);
pTimer1.Enabled = true; pTimer2.Interval = 400;
pTimer2.Tick += new EventHandler(pTimer_Tick);
pTimer2.Enabled = true;
}
private void pTimer_Tick(object sender, System.EventArgs e)
{
if(((Timer)sender == pTimer1))
{
lblTimer1.Text = Convert.ToString(Convert.ToInt32(lblTimer1.Text) + 1);
}
else
{
lblTimer2.Text = Convert.ToString(Convert.ToInt32(lblTimer2.Text) + 1);
}
}
}
}