Task Pane Instance becomes null in Excel 2013 if set to visible false at OnTaskPaneBeforeShow

Add-in Express™ Support Service
That's what is more important than anything else

Task Pane Instance becomes null in Excel 2013 if set to visible false at OnTaskPaneBeforeShow
 
Ramesh Shrestha




Posts: 63
Joined: 2011-01-03
Dear support,

We are working on making our addin compatible with Excel 2013. We have a requirement to make task pane hidden at initial (when excel starts). For that purpose, we write:

private void TaskPane_ADXBeforeTaskPaneShow(object sender, AddinExpress.XL.ADXBeforeTaskPaneShowEventArgs e)
{
// other codes
this.Visible = false;
}

this works.

Now, user will press a button to carry out addin specific process. During this process, we need to open another workbook and close it before the process finishes. We noticed that task pane is created for that second workbook too. Now we understand this is due to SDI architecture of Excel 2013.

The problem is that when the process is finished, and we check for
ADXExcelTaskPane1 aPane = adxExcelTaskPanesCollectionItem1.TaskPaneInstance as ADXExcelTaskPane1;

and the task pane comes null.

We are seeing different behaviour in Debug and Release version of same addin. In Release version, above problem occurs, but in debug version, somehow we see Window Activate event being fired in-between the process start and reading of the task pane instance and it does not come as null.

Is there any workaround to this problem?

We tried using AddinModule_OnSendMessage at end of the process, but it did not help, task pane instance is still null.

Thanks in advance
Ramesh


Posted 04 Apr, 2013 00:52:16 Top
Ramesh Shrestha




Posts: 63
Joined: 2011-01-03
Hi,

I have added a very simple project to demonstrate the problem.

Please download: http://dl.dropbox.com/spa/ymse6uo5hhtvqry/TaskpaneProject.rar

- At first Taskpane will be hidden.
- Pressing Show/hide taskpane works.
- Now click on Open Workbook, then click again on Show/hide taskpane button, Taskpane becomes null.
- Minimize the excel and again maximize, now try the Show/hide taskpane button, it works now, taskpane is not null now.

This is problem in Excel 2013 only, in excel 2007, it is not problem.

Am I missing something here or doing it incorrectly? please advise.

Hope this helps.
Ramesh


http://dl.dropbox.com/spa/ymse6uo5hhtvqry/TaskpaneProject.rar
Posted 04 Apr, 2013 06:52:02 Top
Ramesh Shrestha




Posts: 63
Joined: 2011-01-03
Hi,

I was just wondering if you have any update for me regarding the issue?

Regards
Ramesh
Posted 05 Apr, 2013 01:36:09 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello Ramesh,

The code below works fine for me.

private const int WM_USER = 0x400;
private const int WM_MYMESSAGE = WM_USER + 1800;
Workbook wb = null;

private void adxRibbonButton2_OnClick(object sender, IRibbonControl control, bool pressed)
{
    // just open any excel workbook and close it.
    Excel.Workbooks wbks = ExcelApp.Workbooks;
    wb = wbks.Open(@"d:MyFile.xlsx");
    Marshal.ReleaseComObject(wbks);
    this.SendMessage(WM_MYMESSAGE);             
}

private void AddinModule_OnSendMessage(object sender, ADXSendMessageEventArgs e) {
    if (e.Message == WM_MYMESSAGE && wb != null) {
        wb.Close();
        Marshal.ReleaseComObject(wb);
    }
}


Does it work for you?


Andrei Smolin
Add-in Express Team Leader
Posted 05 Apr, 2013 02:10:49 Top
Ramesh Shrestha




Posts: 63
Joined: 2011-01-03
Hi,

Thank you for the reply. It works well in the demo sample.

However, when I integrated the solution in my real project. It works for the first time only. If I repeat the process, again Task Pane Instance comes null again. The behaviour is same whether task pane pane is visible or hidden before opening the second workbook.

Will it be good idea if I create new task pane if it is found to be null? Will the the Task Pane instance be updated as soon as I create the new one? Or, is there any easier way to tackle this issue?

Anyway, I will do more digging and let you know the updates.

Regards
Ramesh
Posted 05 Apr, 2013 08:21:18 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Ramesh,

In my code, I paid attention to releasing COM objects and to creating a delay between opening the workbooko and closing it. I suggest that you pay attention to these, too.


Andrei Smolin
Add-in Express Team Leader
Posted 05 Apr, 2013 09:07:50 Top
Ramesh Shrestha




Posts: 63
Joined: 2011-01-03
Hi Andrei,

I tried every variation of delay i.e. SendMessage, Threading.Timer, Thread.Sleep or a Dialog box, however it did not work in my case.

After some digging, what I found is that when I set ExcelApp.EnableEvents to true, the task pane instance comes fine.

if (Gconfig.IsRelease)
{
ExcelApp.ScreenUpdating = false;
if(xlVersion != EVersion.XL2013) ExcelApp.EnableEvents = false;
ExcelApp.DisplayAlerts = false;
}

With EnableEvents set to true, I saw that several windows events such as WindowActivate etc. fired between opening and closing the workbook. I think, this may have helped task pane instance to get correct value. But I'm not sure.

Can this setting have any other unwanted impacts to my program?

Regards
Ramesh


[CODE]
Posted 09 Apr, 2013 06:38:10 Top
Andrei Smolin


Add-in Express team


Posts: 18793
Joined: 2006-05-11
Hello Ramesh,

I need to reproduce the issue. Can I have some code for testing? If yes, please send it to the support email address.


Andrei Smolin
Add-in Express Team Leader
Posted 09 Apr, 2013 06:45:19 Top