using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Timers;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
Timer time = new Timer();
time.Elapsed += new ElapsedEventHandler(action);
time.Interval = 5000;
time.Enabled = true;
time.Start();
}
static void action(Object sender, ElapsedEventArgs args)
{
Console.WriteLine("haha\n");
}
}
}
這段代碼沒有任何輸出。誰能告訴我問題是什麼?非常感謝你。我遵循MSDN上的確切代碼。http://msdn.microsoft.com/en-us/library/system.timers.timer(v=vs.71).aspx如何從這段代碼中得不到輸出?
我用CTRL + F5。沒有輸出 –
while(true){} after time.Start();將保持循環。 – Andy