0

I have this task given to me and have no idea how to approach it.. Everywhere online says that this isn't possible without .dll or mocking.

The server, when launched with an argument of –w should open a windowed interface that permits an operator to control the functions of the server. If launched with no arguments it should operate as previously specified in part 1

(part 1 is a console application) I don't know if I'm missing something obvious. Thanks for any help you can give

Mr U
  • 47
  • 1
  • 9

2 Answers2

0

I don't know where you're seeing on-line that this isn't possible. Every Windows Forms application has a Main method, you just need to modify it a bit.

[STAThread]
static void Main(string[] args)
{
    if (args.Length > 0)
    {
        File.WriteAllText("hello.txt", "foo");
    }
    else
    {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        Application.Run(new Form1());
    }
}

I added the string[] args argument and then check it. I'm not checking for -w, I'm just checking for any old argument, but you should be able to take it from there.

Craig W.
  • 17,838
  • 6
  • 49
  • 82
-1

It's absolutely not impossible. Just add reference to System.Windows.Forms, add it in the using clause, and go from here.

using System;
using System.Collections.Generic;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Linq;

namespace ConsoleWindow
{
    class Program
    {
        static void Main(string[] args)
        {
            if (args.Contains("-w"))
            {
                Form1 f1 = new Form1();
                f1.ShowDialog();
            }
            Console.ReadKey();
        }
    }
}
Antoine
  • 148
  • 9