KernelDestroyCode
Mathematica code to run during kernel shutdown
A sample setting is shown below.
<KernelDestroyCode>MyApplication`ShutdownConnection[]</KernelDestroyCode>