1
我注意到,其中出现System.Timers.Timer
对象的使用程序是非常消耗CPU(几乎100PERCENT单CPU核心)。计划与System.Timers.Timer通过Mono项目拼命地跑会导致高CPU负载
我使用Ubuntu 11.10,这里是我的版本单声道:
mono -V
Mono JIT compiler version 2.10.5 (Debian 2.10.5-1)
Copyright (C) 2002-2011 Novell, Inc, Xamarin, Inc and Contributors. www.mono-project.com
TLS: __thread
SIGSEGV: altstack
Notifications: epoll
Architecture: amd64
Disabled: none
Misc: softdebug
LLVM: supported, not enabled.
GC: Included Boehm (with typed GC and Parallel Mark)
下面是示例程序,这会导致意想不到的CPU使用率很高:
using System;
using System.Timers;
namespace MonoCPUTest
{
class Program
{
static Timer _refresh = new Timer();
static void Main(string[] args)
{
_refresh.Interval = 2000;
_refresh.AutoReset = true;
_refresh.Elapsed += (x, y) => refresh();
_refresh.Start();
while (true)
{
Console.WriteLine("loop");
System.Threading.Thread.Sleep(10000);
}
}
static void refresh()
{
Console.WriteLine("refresh");
}
}
}
非常感谢您的任何帮帮我。