Console Application - Exit Code

  • Thread starter Thread starter Mythran
  • Start date Start date
M

Mythran

What is the correct way to set the exit code from within a console
application? Currently we do:

Public Function Main() As Integer
...
Environment.ExitCode = ...
Return Environment.ExitCode
End Function

Should we use Environment.ExitCode And/Or return the exit code?

Thanks,
Mythran
 
Mythran said:
What is the correct way to set the exit code from within a console
application? Currently we do:

Public Function Main() As Integer
...
Environment.ExitCode = ...
Return Environment.ExitCode
End Function

Should we use Environment.ExitCode And/Or return the exit code?

You do not need to (and IMO should not) set 'Environment.ExitCode' if you
return the exit code in the 'Main' function and vice versa.
 
Herfried K. Wagner said:
You do not need to (and IMO should not) set 'Environment.ExitCode' if you
return the exit code in the 'Main' function and vice versa.

After performing some tests, I found that setting Environment.ExitCode does
nothing when Main is defined as a function (and hence, returns a value). If
it is defined as a sub, setting ExitCode sets the exit code. So yes, you
are correct :)

Thanks,
Mythran
 
Mythran said:
After performing some tests, I found that setting Environment.ExitCode
does nothing when Main is defined as a function (and hence, returns a
value). If it is defined as a sub, setting ExitCode sets the exit code.
So yes, you are correct :)

Note that VS.NET 2003 (and maybe VS 2005) didn't show the correct return
value when running the project from within the IDE.
 
Herfried K. Wagner said:
Note that VS.NET 2003 (and maybe VS 2005) didn't show the correct return
value when running the project from within the IDE.

I didn't test running it in the IDE. I had a javascript that ran it and
display the results of the Exec or Run (whichever one it was) function :)

Mythran
 
Back
Top