gjvdkamp
Posts: 56
Joined: 2018-08-28
|
Hi all,
I have a Advanced Takpanes that I only want to show in certain circumstances, so I subscribed to the ADXBeforeTaskPaneShow event to set Visisble to the desired value. To be able to do that I need to get a ref to the workbook to check stuf on it.
This however gave me an error in production for one client, that he says prevents his excel from starting up. From the telemetry I could see that I got a null ref exception on the indicated line. The only way I can understand that if o is null.. I have not been able to reproduce this bug, but he is very annoyed so need to make sure it does not happen again.
Before I just wrap this in checks, I would like to understand how o = WindowObj as Window could be null tho? Without a window, how would the taskpane exist? And could it be anything else than a Microsoft.Office.Interop.Excel.Window object?
private void MapsAndMessagesTaskpane_ADXBeforeTaskPaneShow(object sender, ADXBeforeTaskPaneShowEventArgs e) {
var o = WindowObj as Window;
_wb = o.Parent as Workbook; // <- this line threw a nullreference exception
The docs warn that the Excel objects might not be accessible for NewWorkbook and several other events, but ADXBeforeTaskPaneShow is not in that list..
Thanks in advance,
Gert-Jan |
|
Andrei Smolin
Add-in Express team
Posts: 18826
Joined: 2006-05-11
|
Hello Gert-Jan,
Add-in Express panes are designed around the windowing of the host application, not around its object model. This means the pane may be created (e.g. as a reaction to Excel creating a window) when the corresponding Excel.Window object isn't created yet.
In the {Add-in Express task pane object}.ADXBeforeTaskPaneShow event, check WindowObj. If it is null, set {Add-in Express task pane object}.Visible = false, start a timer, wait for 50-100 ms, check WindowObj again. If it is okay, call {Add-in Express task pane object}.Show(). Note that doing this raise the {Add-in Express task pane object}.ADXBeforeTaskPaneShow once again.
Also, you may need to check if ExcelApp.ActiveWorkbook returns a Workbook object, not null.
Andrei Smolin
Add-in Express Team Leader |
|
gjvdkamp
Posts: 56
Joined: 2018-08-28
|
Thanks Andrei, I'll give that a shot. I take it ADX takes takes care of invoking this background call to the UI thread? |
|
Andrei Smolin
Add-in Express team
Posts: 18826
Joined: 2006-05-11
|
Hello Gert-Jan,
Sorry? What call? Add-in Express doesn't do anything background.
Andrei Smolin
Add-in Express Team Leader |
|
gjvdkamp
Posts: 56
Joined: 2018-08-28
|
Ah wait you probbaly mean a System.Windows.Forms.Timer that fires from the GUI thread itself. A System.Timer would fire from a backgroudn thread and run into trouble when trying to access controls created on the GUI thread. |
|
Andrei Smolin
Add-in Express team
Posts: 18826
Joined: 2006-05-11
|
gjvdkamp writes:
A System.Timer would fire from a backgroudn thread and run into trouble when trying to access controls created on the GUI thread.
Exactly.
Andrei Smolin
Add-in Express Team Leader |
|