我正在用LinuxMint和MonoDevelop開發C#應用程序。
我寫了下面的代碼,
Mono中的多個Windows應用程序的bug
using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Forms;
using System.Threading;
using System.Diagnostics;
namespace TestProgram
{
public static class Program
{
public static int count = 0;
static object locker = new object();
const int limit = 10;
[STAThread]
static void Main()
{
for(int i = 0; i < Program.limit; ++i)
{
Action item =() => Program.RunForm();
item.BeginInvoke((a) => item.EndInvoke(a), null);
Thread.Sleep(1000);
}
while(true)
{
Thread.Sleep(1000);
if(Program.count == 0)
break;
}
return;
}
static void RunForm()
{
lock(Program.locker) {
Program.count += 1;
}
Application.EnableVisualStyles();
Application.Run(new Form());
lock(Program.locker) {
Program.count -= 1;
}
}
}
}
在DOTNET,程序工作正常。 10個窗口顯示正確。
在單聲道中,程序崩潰,沒有託管異常。
當出現第2,第3或更晚的窗口時,它突然崩潰。
這是單聲道的錯誤嗎?或者代碼錯了?
爲什麼行爲不同?
(請原諒我糟糕的英語。)
使用'Thread.Sleep'本身就是一個bug。 – 2012-08-05 17:02:35
下一次請確保您在詢問之前做一些調查,http://www.mono-project.com/FAQ:_Winforms。如果任何問題如此明顯,它必須是一個報告的錯誤或已知的錯誤。 – 2012-08-06 02:47:56