3

In excel I am showing a WPF window which is running on a new thread. There are numerous references to it in stackoverflow this is but one.

The problem is that if the user after opening the WPF window immediately closes Excel, then Excel appears to hang but eventually closes the window. It appears to take a very long time to close the window and call Dispatcher.InvokeShutdown.

Does anyone know of an earlier event in Excel or the Addin than the close event of the window to call Dispatcher.InvokeShutdown? I added a PROC using the Win API on the WPF window but in my testing Excel does not (even though it is the owner of the window) send the standard messages to the window to close.

darbid
  • 2,545
  • 23
  • 55

1 Answers1

2

the cause: excel disposes the taskpanes before raising the shutdown event.

the workaround: (make sure ShowAllFiles is checked else you won't find the designer.vb)

ThisAddin.vb : add your disposal code

Protected Sub PrepareShutdown
  'Close your wpf windows/controls.
  'Including Dispatcher.CurrentDispatcher.InvokeShutdown()
End Sub

ThisAddin.Designer.vb : change existing block to

Protected Overrides Sub OnShutdown()
        PrepareShutdown()
        Me.VstoSmartTags.Dispose()
        Me.CustomTaskPanes.Dispose()
        MyBase.OnShutdown()
End Sub

hth, keepITcool

keepITcool
  • 21
  • 2