static void UninstallAfterCalculateHandler()
 {
     _activeServerCount--;
     if (_activeServerCount <= 0 && _appEventSink != null)
     {
         _connectionPoint.Unadvise(_adviseCookie);
         Marshal.ReleaseComObject(_connectionPoint);
         _connectionPoint = null;
         _appEventSink    = null;
     }
 }
        static void InstallAfterCalculateHandler()
        {
            if (_appEventSink == null)
            {
                object app = ExcelDnaUtil.Application;
                _appEventSink = new AppEventSink();
                IConnectionPointContainer connectionPointContainer = (IConnectionPointContainer)app;
                Guid appEventsInterfaceId = new Guid("00024413-0000-0000-c000-000000000046");
                connectionPointContainer.FindConnectionPoint(ref appEventsInterfaceId, out _connectionPoint);
                _connectionPoint.Advise(_appEventSink, out _adviseCookie);

                _appEventSink.AfterCalculate = AfterCalculate;
            }
            _activeServerCount++;
        }