【发布时间】:2010-10-14 14:06:45
【问题描述】:
我正在尝试让我的基于 WinForm 的 C# 也与命令行配合,但我很难让它发挥得很好。例如,我有这样的代码:
[STAThread]
static void Main(string[] args) {
foreach (string s in args) {
System.Windows.Forms.MessageBox.Show(s);
Console.WriteLine("String: " + s);
}
Mutex appSingleton = new System.Threading.Mutex(false, "WinSyncSingalInstanceMutx");
if (appSingleton.WaitOne(0, false)) {
try {
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//start logger
Logger.singleton.makeOpen(true);
Application.Run(new MainForm(false));
} catch (Exception) {
} finally {
appSingleton.Close();
Logger.singleton.makeOpen(false);
}
} else {
System.Windows.Forms.MessageBox.Show("Sorry, only one instance of WinSync can be ran at once.");
}
}
}
它应该使用 Console.WriteLine 写入控制台,但我什么也没看到,只有 MessageBox 出现。
我做错了什么?
【问题讨论】:
标签: c# .net user-interface console