Search code examples
c#azure-functionsexitazure-functions-runtime

What does Environment.Exit do when run in Azure Functions?


With Azure WebJobs, you can force a restart of a webjob process by calling Environment.Exit and returning. This forces a restart of the webjob which in my case reloaded a bugged out external dll that I had.. I´ve recently moved some code from WebJobs to functions (v1 for legacy reasons), and I haven't been able to find any information as to what happens when you use Environment.Exit in an Azure Function. Does the entire Function server exit? Does only the current invocation exit? What happens?


Solution

  • Actually the method in the doc has described what Environment.Exit would do. If you run it local, it will just terminate the process and you app won't restart.

    However in azure the windows Azure Function is host with IIS, the IIS process couldn't be terminate totally. The method only kill the process temporarily and it won't restart it too, however if you try to request the HTTP trigger url or add the queue message with queue trigger, it will start the process.

    Also it won't just kill its own process, if you have HTTP trigger and Queue trigger functions, you use Environment.Exit kill one process, the other will be killed too it also need a time to start with trigger.