Karthik
Karthik

Reputation: 79

Azure function HTTP trigger stop eventhandler

On an AzureFunction, as and when Http message is received I am doing a POST to an external server(3rd party server) through the Function code.

To maintain one connection for ALL the devices, I have hosted the Azure Function on a Server rather than Consumption plan and also creating static httpClient to POST to the external server.

When the Azure Function APP is stopped, I need an eventhandler to unsubscribe from the external server. But I am unable to find a STOP eventhandler for Azure Function. Any suggestions ?

Upvotes: 0

Views: 315

Answers (1)

rickvdbosch
rickvdbosch

Reputation: 15621

There is no OnStop event or something like that you can use to run custom code when your Function stops since Azure Functions hide the app lifecycle.

You could hook into the AppDomain. Try something like this:

AppDomain.CurrentDomain.ProcessExit += (sender, eventArgs) => 
{
    // Your custom code
};

Upvotes: 1

Related Questions