Timer 事件中的 执行时间 超过 设定的周期。1、MSDN上说 后面的 线程会等待前面的结束,所以 当我后面还有 50个线程 等待执行(因为前面超时的原因),我stop 计时器后面的 线程不会增加 但是会继续执行。问题来了。。这些线程 执行完了 不会自动退出using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using pSpaceCTLNET;
using System.Threading;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
t.Interval = 100;
t.Elapsed += new System.Timers.ElapsedEventHandler(t_Elapsed);
t.Disposed += new EventHandler(t_Disposed);
t.Start();
while (Console.ReadLine()!="Y")
{
}
t.Stop();
Console.WriteLine("已停止");
t.Dispose();
Console.WriteLine("以释放");
Console.ReadLine();
} static void t_Disposed(object sender, EventArgs e)
{
Console.WriteLine("释放事件");
t.Container.Dispose();
} static void t_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{ Thread.Sleep(10000);
Console.WriteLine("a"+DateTime.Now);
}
static System.Timers.Timer t = new System.Timers.Timer();
}
}
using System.Collections.Generic;
using System.Linq;
using System.Text;
using pSpaceCTLNET;
using System.Threading;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
t.Interval = 100;
t.Elapsed += new System.Timers.ElapsedEventHandler(t_Elapsed);
t.Disposed += new EventHandler(t_Disposed);
t.Start();
while (Console.ReadLine()!="Y")
{
}
t.Stop();
Console.WriteLine("已停止");
t.Dispose();
Console.WriteLine("以释放");
Console.ReadLine();
} static void t_Disposed(object sender, EventArgs e)
{
Console.WriteLine("释放事件");
t.Container.Dispose();
} static void t_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
{ Thread.Sleep(10000);
Console.WriteLine("a"+DateTime.Now);
}
static System.Timers.Timer t = new System.Timers.Timer();
}
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货