Question

I try to convert the class Program of Console Application to a regular class, in order to integrate it in a Windows Application project.

I would like to invoke the void Main method. What parameters should I send it?

In Class Program:

public static void Main(string[] args)

In another class :

Program.Main(?);

Was it helpful?

Solution

If what you are trying to achieve is to pass to Program.Main() the arguments that were passed when the Windows application executable is started, you could do:

Program.Main(Environment.GetCommandLineArgs());

However, it's a bad idea to keep your method as 'Main', because you'll end up with 2 main methods in your Windows application (one created by Visual Studio, and yours).

OTHER TIPS

I agree with the others, I don't see the problem...

Anyway, the args string array contains the args given to the assembly when launched. For instance :

"C:\myApp.exe arg1 arg2 arg3"

The first one is the called executable then arg1, arg2 and arg3. (a size 4 array).

If you want to call Main like through the CLI just do something like :

Programe.Main(new string[] {String.Empty, "arg1", "arg2", "arg3"});

After it will always depend on the way you use the parameters within your CLI application.

A good idea would be to refactor your application and use Program.Main as the CLI entry point but not the "application" entry point. So you'll be able to use several entry point to the same logic.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top