Frage

i have changed my Main:

[STAThread]
static void Main(string[] args)
{
    if (args.Length == 0)
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new fForm());
    }
    else
    {
        Console.WriteLine("Yay! I have just created a commandline tool.");
    }
}

But how can i print this massage Console.WriteLine(...) ? currently nothing happen when send argument into my exe file

War es hilfreich?

Lösung

If you're okay with the console always being visible, you can change your project's Output Type (in project properties) to "Console Application."

Andere Tipps

Duplicate question answer here: https://stackoverflow.com/a/15079092/666899

Essentially, what you have to do is manually create the console window via Win32 (pinvoke).

edit: To further clarify, you cannot have a console if your app is set to Windows Application, and you cannot rid of the Console if your app is a console application and you only want UI. Either way you have to call the native Win32 functions to either hide the console, or create it depending on the situation.

If you check the Output window in Visual Studio you'll probably find that it has the WriteLine message in it. Because there's nothing after it the application exits at that point which may appear as if nothing has happened

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top