Word standard taskpanes duplicated issue

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

Word standard taskpanes duplicated issue
 
R. Damien




Posts: 10
Joined: 2014-04-28
Hello,

I created a Word addin with a taskpane designed with WPF.
To do that, I followed this post http://www.add-in-express.com/creating-addins-blog/2010/07/20/windows-presentation-foundation/.

I have a strange issue : The taskpane is duplicated in Word Window, Taskpane is duplicated again each time we
open/close/reopen document, or by switchin active window. It's like a new Taskpane instance is created each time.

This strange behavior occurs randomly on different PCs :
- not reproductible on some pcs,
- occurs sometimes (rarely) on others pcs,
- occurs each time we play explained scenario on one another pc

Tests contexts :
- Each testeds PCs used Word 2010,
- Each testeds PCs have not other Word addins.
- My test addin to reproduce this issue is without code, only addinmodule + one Word ribbon + one WPF taskpane

We noticed that winword.exe process remains after word is closed when this issue occurs. I read this post http://www.add-in-express.com/creating-addins-blog/2013/11/05/release-excel-com-objects/ but I have no code in my test addin.

I don't understand. Have you any idea ?

--
PS : Another question : to retrieve the task pane associated with a current Word window, it's a good way to use adxTaskPane1[ActiveWindow] accessor ?

Thanks for you help.
Posted 22 Oct, 2014 04:54:43 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Damien,

Thank you for the detailed description.

I have just created a small test add-in for Microsoft Word based on the description of our http://www.add-in-express.com/creating-addins-blog/2010/07/20/windows-presentation-foundation/ blog post. I cannot reproduce the issue you described in Word 2010.

I need to know more details about the affected machines. Also, please let me know what Add-in Express version you use.


PS : Another question : to retrieve the task pane associated with a current Word window, it's a good way to use adxTaskPane1[ActiveWindow] accessor ?


Yes, you can use this accessor. Please see the code sample below:

private void adxRibbonButton1_OnClick(object sender, IRibbonControl control, bool pressed)
{
    if (adxTaskPane1.IsConnected)
    {
        Word.Window activeWnd = WordApp.ActiveWindow;
        if (activeWnd != null)
            try
            {
                ADXTaskPane.ADXCustomTaskPaneInstance instance = adxTaskPane1[activeWnd];
                if (instance != null)
                {
                    ctlCustomerLimit currentControl = instance.Control as ctlCustomerLimit;
                    if (currentControl != null)
                    {
                        currentControl.label1.Text = "Changed " + Environment.TickCount.ToString();
                    }
                }
            }
        finally {Marshal.ReleaseComObject(activeWnd);}
    }
}
Posted 22 Oct, 2014 07:10:55 Top
R. Damien




Posts: 10
Joined: 2014-04-28
Hello Dmitry,

Thanks for your response.

We use the last Addin Express version 7.5.40.72

Me too, I can't reproduce issue on all machines (Win 7 , Word 2010), it's really hard to understand and debug.

Here is the only code I have in my described test addin:


//AddinModule.cs
 private void adxWordEvents_WindowSelectionChange(object sender, object hostObj)
 {
 	try
 	{            
            sel = hostObj as Word.Selection;
            doc = sel.Document;
           
            // INFO : addText is a public method of my taskpane user control which set text (for test)
            this.getPncTaskPaneUC(doc.ActiveWindow).addText("selection change on "+doc.FullName);
        }
        finally
        {
            if (doc != null)
                Marshal.ReleaseComObject(doc);
            if (sel != null)
                Marshal.ReleaseComObject(sel);
        }
    }
  }

public AddinExpress.MSO.ADXTaskPane.ADXCustomTaskPaneInstance getPncTaskPaneInstance(Word.Window w)
{    
    return AddinModule.CurrentInstance.adxTaskPane1[w];
}
       
public UserControl1 getPncTaskPaneUC(Word.Window w)
{
    AddinExpress.MSO.ADXTaskPane.ADXCustomTaskPaneInstance tp = getPncTaskPaneInstance(w);

    UserControl1 uc = tp.Control as UserControl1;

    return uc;
}


Maybe something is wrong ?

When Alt+tab to switch opened Word Windows, it's like that instead retrieving window taskpane current instance, a new one is created each time. I see in your code sample that you test adxTaskPane1.IsConnected, maybe I can try to add this.. but without much hope.

Thanks, really.
Posted 22 Oct, 2014 08:49:57 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hello Damien,

I see just two issues in your code:
1. You don't need to release the sel variable in the WindowSelectionChange event handler.
2. You get the Word.Window instance in the following code line but do not release it:

this.getPncTaskPaneUC(doc.ActiveWindow).addText("selection change on "+doc.FullName); 


I have just added this code to my test add-in but am still unable to reproduce the issue.


Damien, please provide more details about the affected machines. How many reports do you have? What do these reports have in common?
Posted 22 Oct, 2014 10:03:52 Top
R. Damien




Posts: 10
Joined: 2014-04-28
Dmitry,

1/ So, why I don't need to release the sel variable ? Can you explain me please ?

2/ Indeed, I forget to release the Word.Window and I wonder if could be the issue reason ? (Not release base objects can occur obscur issues no?)

3/ For reports, in our team of 4 pcs Win7 + Word 2010, I see :
- 1 pc without issue, never (mine, maybe because I have a "dev" env with Visual Studio ?)
- 2 pcs where issue occurs sometimes, but rather rarely.
- 1 pc which reproduce issue each time we open / close / switch with multiple Word Documents.

As I say, these reports have in common that winword.exe process remains after word is closed. That's why I think release Word base objects might be the reason of issue ? I'll trying to release the forgotten Word.Window and see results on the most affected machine.

Otherwise, do you see other ways / informations to help me in debugging?
Posted 22 Oct, 2014 10:41:24 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Damien,

1/ So, why I don't need to release the sel variable ? Can you explain me please ?


Sure. It is the incoming parameter of the WindowSelectionChange event. The Add-in Express code releases it. You can find more details about the proper usage Marshal.ReleaseComObject in the
http://www.add-in-express.com/creating-addins-blog/2008/10/30/releasing-office-objects-net/ blog post.

2/ Indeed, I forget to release the Word.Window and I wonder if could be the issue reason ? (Not release base objects can occur obscur issues no?)


I doubt this may cause the issue. As I mentioned in my previous post, I have tested your code and was not able to reproduce the problem.


- 2 pcs where issue occurs sometimes, but rather rarely.
- 1 pc which reproduce issue each time we open / close / switch with multiple Word Documents.


Is the the same version of Microsoft Word (including Service Packs and updates) installed on these machines? Are any other COM add-ins for Word installed on these machines?
Posted 23 Oct, 2014 07:56:38 Top
R. Damien




Posts: 10
Joined: 2014-04-28
Hello Dmitry,

I was able to reproduce the issue on my own machine. In fact issue seems occur when you open document directly from Windows Explorer, with Explorer configured with preview document mode ( Word Document preview appears in a Explorer panel). If I close and reopen document, Taskpane is cloned.

Can you retry ? And how to "hack" Addin Startup / initialize to reset taskpane or other way?

Thanks to help,

EDIT : I also found a old post speaking the preview pane issue https://social.msdn.microsoft.com/Forums/office/en-US/fb72e113-c65c-4d79-8188-d3bb548939cc/excel-2010-com-addin-windows-7-preview-pane-issue?forum=exceldev
Posted 24 Oct, 2014 11:11:42 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Damien,

Thank you for the details, I have just reproduced the issue.

On my side, it occurs in Word 2010 only, Word 2013 works as expected. Our developers will check the code, probably they will find a cause of the issue and fix it.

And how to "hack" Addin Startup / initialize to reset taskpane or other way?


I am afraid nothing can be done from your add-in's code. I would suggest using Advanced Task Panes for now.

EDIT : I also found a old post speaking the preview pane issue


This thread relates to Microsoft Excel, not Word.
Posted 27 Oct, 2014 08:16:38 Top
R. Damien




Posts: 10
Joined: 2014-04-28
Hi Dmitry,

Thanks for your tracking.

Our developers will check the code, probably they will find a cause of the issue and fix it.


Hum, could you tell me when your dev team will be plan to fixe this issue ?
I need to know if I can wait your fixe or If I choose to recode addin with Advanced Task Pane as you suggested.

I would suggest using Advanced Task Panes for now.


Ok, I don't have really much time to recode addin. So, could you help me to understand difference between Advanced and standard taskpanes? What I Should pay attention? Advanced Task panes is document level to ? How Can i retry a advanced task pane instance (of the current window for example) ? Can I use WPF Guest control in a Win form Host in your Advanced task pane ?

Thanks
Posted 27 Oct, 2014 12:59:15 Top
Dmitry Kostochko


Add-in Express team


Posts: 2875
Joined: 2004-04-05
Hi Damien,

Hum, could you tell me when your dev team will be plan to fixe this issue ?


I think we will have some results next week.

What I Should pay attention?


Please pay attention to the events of an advanced task pane. The advanced task pane's state and visiblility can be changed by using its event handlers.

Advanced Task panes is document level to?


They are window level. I.e. each window of a document can have an advanced task pane.

How Can i retry a advanced task pane instance (of the current window for example)?


You can use the CurrentTaskPaneInstance property of the ADXWordTaskPanesCollectionItem class.

Can I use WPF Guest control in a Win form Host in your Advanced task pane ?


Yes, you use it in the same way as on the native Office Custom Task Pane.
Posted 28 Oct, 2014 07:22:25 Top