none
how to make c# form application to be able to run with parmeters from cmd? RRS feed

  • Frage

  • Hi Together

    I have a form application and would like to be able to run it as form application but also from cmd giving some Parameters.

    I tried following down below but i dont get any output result in cmd.

    It seems to be executed but no Output.

    This is how my Programm main() method Looks like.

    If i run it with Parameters in visual Studio it is going into the else Statement and form is not started.

    Whisch is ok.

    If i start exe from cmd with Parameters i dont get any Output.

    Do you know what is the Problem?

    Thanks in advanc for yoour help.

    static void Main(string[] args)
            {
                args = Environment.GetCommandLineArgs();
                if(args.Length ==1)
                {
                    
                    
                    Application.EnableVisualStyles();
                    Application.SetCompatibleTextRenderingDefault(false);
                    Application.Run(new Form1());
    
    
    
                }
                else
                {
                                    foreach (Object obj in args)
                    {
                        Console.WriteLine(obj);
                    }
                    Console.WriteLine("We'll run as a console app now");
                    Console.Read();
    
                }
    
            }

    Donnerstag, 24. Januar 2019 20:13

Antworten

Alle Antworten

  • Hi,

    in der Regel würde ich hier zwei Anwendungen und eine Library vorschlagen.

    Die gesamte Logik wird dann in die Library ausgelagert und die Anwendungen selbst sind für die Aufrufe und die Ausgaben zuständig.


    Gruß, Stefan
    Microsoft MVP - Visual Developer ASP/ASP.NET (2001-2018)
    https://www.asp-solutions.de/ - IT Beratung, Softwareentwicklung, Remotesupport

    Donnerstag, 24. Januar 2019 22:20
    Moderator
  • Hallo Dimitar

    Danke für deine Antwort.

    Habe auch inzwischen gedacht ich mache eine separate console application für die Aufgabe.

    Danke und Grusss

    Dienstag, 29. Januar 2019 09:31