Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

228
Vistas
Process exit code is zero when server running

I have a test suite, with a Main function that returns 1. However, the exit code after the application terminates is 0.

This seems to be related to a ASP.NET server I'm running in the background. If I disable the server, the exit code is 1 as expected.

This code works as expected, and the console reports an exit code of 1 (this is F# syntax, but I'm pretty sure that's not related):

[<EntryPoint>
let main (arts : string array) : int =
  1

while this has an exit code of 0, which is not what I expect:

[<EntryPoint>
let main (arts : string array) : int =
  MyHttpServer.init()
  1

Here's the MyHttpServer.init function:

let init() : Task =
  Host
     .CreateDefaultBuilder()
     .Build()
     .RunAsync()

My question: what is it about having a server running in the background that is causing the exit code to be zero? Is there something in .NET where the exit code is affected by background tasks and threads?

Note: .NET 6 preview 5, but this has happened on all versions I've used from .NET 5 onwards.

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Not super familiar with F# syntax, BUT I suspect that if Init() exits b/c of an error/exception, then execution would never reach the line returning a 1, and would therefore exit with a value of 0.

EDIT: If an exception is thrown when calling Init, or if an exception is thrown before Init can return, the unhandled exception would terminate the process, and the code that returns 1 would not be executed.

over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda