我写的类如下:
public class Class1
    {
        public System.Windows.Forms.Timer ab = new System.Windows.Forms.Timer();        public void Init()
        {
            ab.Interval = 1000;
            ab.Enabled = true;
            ab.Tick += new EventHandler(cuiyh);
        }
        
        public void  cuiyh(object sender, EventArgs e)
        {            Console.WriteLine("cuiyh");
            
        }
    }
我写的控制台程序如下:
using System;
using System.Collections.Generic;
using System.Text;
using YHuaSoft;
namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            YHuaSoft.Class1 ac = new Class1();
            ac.Init();
            Console.ReadLine();
        }
    }
}
为什么在控制台程序中,不连续输出“cuiyh”,谢谢,在线等!!!

解决方案 »

  1.   

    to 为什么在控制台程序中,不连续输出“cuiyh”,谢谢,在线等!!!不要用“System.Windows.Forms.Timer”这个timer类型,用“System.Threading.Timer”这个Timer类型,至于如何用,参看msdn的帮助。
      

  2.   

    我觉得你的调用顺序有问题,           ab.Interval = 1000;
               ab.Enabled = true;
               ab.Tick += new EventHandler(cuiyh);=>应该先绑定事件,再打开定时器。           ab.Tick += new EventHandler(cuiyh);
               ab.Interval = 1000;
               ab.Enabled = true;
      

  3.   

    http://community.csdn.net/Expert/topic/5045/5045049.xml?temp=.7106897
    借点人气 找人帮帮忙