You should capture the event for Shutdown, CompanyChange, ServerTermination. Here's my sample:
Private Sub SBO_Application_AppEvent(ByVal EventType As SAPbouiCOM.BoAppEventTypes) Handles SBO_Application.AppEvent
Try
Select Case EventType
Case SAPbouiCOM.BoAppEventTypes.aet_ShutDown, _
SAPbouiCOM.BoAppEventTypes.aet_ServerTerminition
'Release the resource and exit
RemoveMenus()
Application.Exit()
Case SAPbouiCOM.BoAppEventTypes.aet_CompanyChanged
Application.Exit()
Case SAPbouiCOM.BoAppEventTypes.aet_ShutDown
SAP_APP.SetMessage("Add-on is Shutting down..", SAPbouiCOM.BoStatusBarMessageType.smt_Success)
Application.Exit()
End Select
Catch ex As Exception
SAP_App.SetMessage(ex.Message, SAPbouiCOM.BoStatusBarMessageType.smt_Error)
End Try
End Sub