title: VSTO- word taskpane share in multiple document with value issue
body: <p>i am create a addin using VSTO with c#,</p>
  
  <p>i have create a user control for task-pane, where i have following controls:
  1) a text-box- for word document folder,
  2) a button - for browsing throw specified folder in the text box,
  3) a tree view control to display all the files and folder on the specified path in the text-box,</p>
  
  <p>these are working fine. when i select a document from tree-view it open without the task pane.</p>
  
  <p>i have written the following code for document select.</p>
  
  <pre><code>private void treeFiles_NodeMouseDoubleClick(object sender, TreeNodeMouseClickEventArgs e)
      {
          string fullPath = e.Node.Name;
          string checkExt = Path.GetExtension(fullPath);
          if (checkExt.Contains("doc"))
          {
              //System.Diagnostics.Process.Start(fullPath);
              object fileName = fullPath;
              object readOnly = false;
              object isVisible = true;
              // Here is the way to handle parameters you don't care about in .NET
              object missing = System.Reflection.Missing.Value;
  
              // Make word visible, so you can see what's happening         
              Globals.MainPage.Application.Visible = true;
  
              Word.Document aDoc = Globals.MainPage.Application.Documents.Open(ref fileName, ref missing, ref readOnly, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref isVisible);
  
              // Activate the document so it shows up in front
              aDoc.Activate();
          }
      }
  </code></pre>
  
  <p>in the main file i have written the following code:</p>
  
  <pre><code>    HomeControl objHomeControl;
  
      public static Microsoft.Office.Tools.CustomTaskPane taskPaneValue;
  
      private void ThisAddIn_Startup(object sender, System.EventArgs e)
      {
          objHomeControl = new HomeControl();
          taskPaneValue = this.CustomTaskPanes.Add(objHomeControl, "File task pane");
          taskPaneValue.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionLeft;
          taskPaneValue.VisibleChanged += new EventHandler(taskPaneValue_VisibleChanged);
          taskPaneValue.Visible = true;
          this.Application.DocumentOpen += new Word.ApplicationEvents4_DocumentOpenEventHandler(Application_DocumentOpen);
  
      }
  
      void Application_DocumentOpen(Word.Document Doc)
      {
          HomeControl objHomeControl1 = new HomeControl();
          taskPaneValue = this.CustomTaskPanes.Add(objHomeControl1, "File task pane",Doc.ActiveWindow);
          taskPaneValue.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionLeft;
          taskPaneValue.VisibleChanged += new EventHandler(taskPaneValue_VisibleChanged);
          taskPaneValue.Visible = true;
      }
  
      void taskPaneValue_VisibleChanged(object sender, EventArgs e)
      {
          Globals.Ribbons.MyRibbon.tgleButton.Checked = taskPaneValue.Visible;
  
      }
  
      public Microsoft.Office.Tools.CustomTaskPane TaskPane
      {
          get
          {
              return taskPaneValue;
          }
      }
  </code></pre>
  
  <p>when i double click on the node, document open  but it add in(UserControl) reinitialized. all the values get reset, add in on/off from ribbon does not work. how can i make a single copy of the UserControl share across all the document.</p>
  
  <p>i have also tried this</p>
  
  <pre><code>    void Application_DocumentOpen(Word.Document Doc)
      {
          taskPaneValue = this.CustomTaskPanes.Add(objHomeControl, "File task pane",Doc.ActiveWindow);
          taskPaneValue.DockPosition = Office.MsoCTPDockPosition.msoCTPDockPositionLeft;
          taskPaneValue.VisibleChanged += new EventHandler(taskPaneValue_VisibleChanged);
          taskPaneValue.Visible = true;
      }
  </code></pre>
  
  <p>it open the taskpane in the new document. but does not allow me click anywhere. if i click on the parent document, i get the following an exception message:</p>
  
  <p>"COM object that has been separated from its underlying RCW cannot be used."</p>
  
  <p>Help me out.</p>