.net
C#: Kombination aus Forms- und Konsolenanwendung
Um Forms- und Konsolenanwendung in einer einzigen Assembly zu kombinieren, gibt es (mindestens) zwei Möglichkeiten. Keine davon ist zu 100% perfekt.
Möglichkeit 1
Hier muss die Assembly als Windows Forms Anwendung konfiguriert sein.
Code-Beispiel:
using System;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace MyProject
{
static class Program
{
[DllImport("kernel32.dll")]
static extern bool FreeConsole();
[STAThread]
static void Main(string[] args)
{
if (args.Length == 0)
{
FreeConsole();
StartUI();
}
else
{
for(int i = 0; i < args.Length;i++)
{
// do something...
}
}
}
private static void StartUI()
{
