2012-09-09 33 views
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"); 
     } 
    } 
} 

非常感谢您的任何帮帮我。

回答

1

我刚刚测试过(通过复制粘贴,编译和执行代码),无法重现问题,CPU负载大约为0.我使用较新版本的Mono,特别是从git树编译的版本前几天;所以如果有这样的问题,它是固定的。

我猜升级Mono是不可能没有外部PPA,但这是如果你没有被迫使用该版本的一些其他原因是什么应该在这里完成。您也可以编译一个来自源,这是容易的,因为配置,制作,安装制作;)

相关问题