2009-11-19 30 views
1

我使用monodevelop編譯我的應用程序。並嘗試在Linux上使用單聲道運行。看來System.Windows.Forms.Timer對象的刻度事件從不會觸發。System.Windows.Forms.Timer事件在單聲道下運行時根本不會觸發

它在Windows上沒有問題,但在Linux中沒有問題。

相關的代碼大致是這樣的:

// derived from a From 
//... 
private Timer controlTimer; 
//.... 
protected override OnCreateControl(/*...*/) 
{ 
//,,, 
    controlTimer=new Timer(); 
    controlTimer.Tick += new EventHandler(controlFunc); 
    controlTimer.Interval = 40; 
    controlTimer.Tag = this; // The form is used by the callback 
    controlTimer.Start(); 
//... 
} 
//.... 
+0

這是什麼版本的單聲道?類似的代碼在這裏工作正常... – Gonzalo 2009-11-19 15:34:35

+0

$ mono -V 單聲道JIT編譯器版本2.4.2.3(Debian 2.4.2.3 + dfsg-2) 版權所有(C)2002-2008 Novell,Inc和Contributors。 www.mono-project.com \t TLS:__thread \t GC:包括伯姆(有類型的GC) \t SIGSEGV:altstack \t聲明:epoll的 \t架構:86 \t禁用:無 – Calmarius 2009-11-20 11:10:33

回答

1

即使simpliest WinForm應用程序並不運行在單計時器...

但是,如果我初始化放置到Form1_Load然後將其添加到form.load事件運行。

編輯:OnCreateControl工作,如果你把一個base.OnCreateControl()在方法的結尾。 在.NET上,它的工作原理沒有這條線,並在單聲道之前工作...

所以它似乎是單聲道的錯誤,我會報告它。

0

我建議你OnControlCreated方法添加Console.WriteLine,以確保該方法獲取調用並確實正在創建的計時器。

1

使用try System.Timers代替Windows.Forms.Timer

看到:很多事情從Windows.Forms的Timer won't tick

也似乎沒有在單聲道都可以實現(例如調用)

已修復它給我。