通过mono项目运行System.Timers.Timer的程序会导致高CPU负载

通过mono项目运行System.Timers.Timer的程序会导致高CPU负载,mono,cpu-usage,Mono,Cpu Usage,我注意到,出现System.Timers.Timer对象的程序非常消耗CPU(单CPU核心几乎100%) 我正在使用Ubuntu 11.10,以下是我的mono版本: 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:

我注意到,出现
System.Timers.Timer
对象的程序非常消耗CPU(单CPU核心几乎100%)

我正在使用Ubuntu 11.10,以下是我的mono版本:

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");
        }
    }
}
非常感谢您的帮助。

我刚刚进行了测试(通过复制粘贴、编译和执行您的代码),无法重现该问题,CPU负载约为0。我正在使用更新版本的Mono,特别是几天前从git树编译的版本;因此,如果有这样的问题,它是固定的

我想如果没有外部PPA,升级Mono是不可能的,但是如果你不是因为其他原因被迫使用这个版本,这就是应该做的。您还可以从源代码处编译一个,这与configure、make、make install;)一样简单

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

我想如果没有外部PPA,升级Mono是不可能的,但是如果你不是因为其他原因被迫使用这个版本,这就是应该做的。您还可以从源代码处编译一个,这与configure、make、make install;)一样简单