0

I have an installer app which is a WinEXE app. And the installation takes around 30 seconds.

As EXE needs arguments, it's recommended to install using Command Prompt or Powershell.

So, when the command is executed, immediately console is available to execute the next command because it didn't till the previous command execution was completed successfully.

As it's a silent installation user will be confused about what's happening in the background and would more likely execute the installation command again.

Other than manually adding a condition in code if EXE is already running, is there any other option available to handle this scenario?

This is reproducible with any sample code.

    static void Main(string[] args)
    {

        for (int i = 0; i < 15; i++)
        {
            Console.WriteLine(i);
            Thread.Sleep(1000);
        }
        Console.WriteLine("Done!!!");

    }

Note : The logs won't be shown for WinEXE. To understand more, it can be converted to Console APP where logs would be shown and it would wait as well.

The app output type is "Windows Application". Please check it in project properties.

The framework is .NET Framework 4.6.1

Assuming the EXE name was MyApp.exe, the command used to execute is -

 Command Prompt: MyApp.exe Argument1 Argument2
 Powershell: .\MyApp.exe Argument1 Argument2
Vaibhav More
  • 212
  • 1
  • 14
  • which framework ? core ?, framework? which version? – Selvin Oct 20 '21 at 11:46
  • It's .NET Framework 4.6.1 – Vaibhav More Oct 20 '21 at 11:48
  • Erm, no. If it's a _silent_ install, I absolutely wouldn't _"be confused about what's happening in the background and would more likely execute the installation command again"_. I actually would want it to be as _silent_ as can be. If I wanted to be informed about the progress of the installation, I'd chose to use a _non-silent_ mode. – Fildor Oct 20 '21 at 12:04
  • "So, when the command is executed, immediately console is available" - _what_ command? Please update your post with the actual statement/command you're running that returns immediately – Mathias R. Jessen Oct 20 '21 at 12:24
  • @MathiasR.Jessen, updated the post with commands. – Vaibhav More Oct 20 '21 at 12:45
  • @Fildor, it's silent by default due to WinEXE where it doesn't show console logs. Even in a non-silent mode, the same behaviour would happen. Please refer above commands. – Vaibhav More Oct 20 '21 at 12:45
  • @VaibhavMore I'm unable to reproduce the behavior you're describing - compiling a console app with the given `Main()` method and launching it with `name.exe argument1 argument2` outputs integers 0 through 14 over 15 seconds before returning – Mathias R. Jessen Oct 20 '21 at 12:48
  • @MathiasR.Jessen Please change the output type to Windows Application from the properties of the project and try the behaviour. – Vaibhav More Oct 20 '21 at 12:54
  • 1
    Ahh, I see it now. Looks like the compiler [sets a flag indicating it's a GUI application, not a console application](https://stackoverflow.com/a/924764/712649) when you use `winexe` as the target output type - which then in turns [causes the runtime to not acquire and a attach a console host on startup](https://stackoverflow.com/questions/4866352/what-are-the-effects-of-the-pe-header-subsystem-field). What's the motivation for using the `winexe` target type? – Mathias R. Jessen Oct 20 '21 at 13:11
  • @MathiasR.Jessen, ah get it. I didn't want to show any console to the user hence using WinEXE output type. In case of console it waits though it shows console which is not required for the user. – Vaibhav More Oct 20 '21 at 13:18
  • I still don't get what behavior it is that you actually _want_? Do you just want to "block" the console until it's done without any outputs? – Fildor Oct 20 '21 at 13:27
  • 1
    @Fildor, yes I want to block the console until it's done without any outputs – Vaibhav More Oct 20 '21 at 13:30
  • ^^ I see some solutions here: a) instead of a tailor-made self-written installer app, actually create an Installer Project. Or b) don't use Console.WriteLine, but an actual logging framework that you set to Console-Output. Then you can switch output verbosity simply by defining the log-level. ... – Fildor Oct 20 '21 at 13:31
  • @Fildor, logging is not a problem. It can be removed from the console. I can try creating an installer project. Would the installer accept arguments dynamically? – Vaibhav More Oct 20 '21 at 13:35
  • Yes of course, you could remove all Console.WriteLine. The advantage of output through a logging framework is: you could have it default to "OFF" = Silent. Now, If you needed _some_ output - maybe to track an error during installation - you could pass a cmd line switch to raise the loglevel to "ERROR" for example, and it would output (hopefully) usable error messages ... you get the idea. – Fildor Oct 20 '21 at 13:43
  • Yes, that's possible and I have both file and console logging. The issue I am trying to resolve is waiting in the console installation is complete. – Vaibhav More Oct 20 '21 at 13:59

0 Answers0