none
OneNote getPageContent method takes 10 - 15 seconds to run RRS feed

  • Question

  • Hi,

    I originally posted this under "Office 2010 - IT Pro General Discussions" but the moderator suggested I move it here.

    I'm writing a OneNote 2010 Add-In using C# and Microsoft.Office.Interop.OneNote, and a call to getPageContent takes between 10 and 15 seconds to run, during which OneNote does not respond to user interaction. The page whose content I'm getting is somewhat large -- it has a single table with 2 columns and roughly 1,500 rows, with roughly 10,000 words total from across the table.

    I'm running getPageContent in its own thread, but this doesn't seem to help. OneNote doesn't appear to respond to user input while the method is running, no matter what thread the method is called from within (as far as I can tell).

    The notebook is on a remote SharePoint server, but the issue remains even when working offline. 

    Below is my code (pared down to isolate the issue), the line in question in bold.

    Any ideas how I could speed this up, or if I'm doing something wrong in general (I'm fairly new to C# / add-in development)?

    Thanks in advance,
    Neil 

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Runtime.InteropServices;
    using Extensibility;
    using Microsoft.Office.Interop.OneNote;
    using Microsoft.Office.Core;
    using System.Windows.Forms;
    using System.Runtime.InteropServices.ComTypes;
    using System.Drawing.Imaging;
    using System.IO;
    using System.Xml.Linq;
    using System.Threading;
    
    namespace NeilOneNote
    {
        [GuidAttribute("8C1483FF-EEDD-4658-9D17-6BCE348106BF"),ProgId("NeilOneNote.Class1")]
        public class Class1 : IDTExtensibility2, IRibbonExtensibility
        {
            ApplicationClass onApp = new ApplicationClass();
            public void OnAddInsUpdate(ref Array custom)
            {   
            }
    
            public void OnBeginShutdown(ref Array custom)
            {
                if (onApp != null)
                    onApp = null;
            }
            
            public void OnConnection(object Application, ext_ConnectMode ConnectMode, object AddInInst, ref Array custom)
            {
                onApp = (ApplicationClass)Application;
            }
    
            public void OnDisconnection(ext_DisconnectMode RemoveMode, ref Array custom)
            {
                onApp = null;
                GC.Collect();
                GC.WaitForPendingFinalizers();
            }
    
            public void OnStartupComplete(ref Array custom)
            {         
            }
    
            public string GetCustomUI(string RibbonID)
            {
                return Properties.Resources.ribbon;
            }
    
            public void showHello(IRibbonControl control)
            {
                ThreadStart childref = new ThreadStart(createLinks);
                Thread childThread = new Thread(childref);
                childThread.Start();
            }
    
            public void createLinks()
            {
                string notebookXml;
                onApp.GetHierarchy(null, HierarchyScope.hsPages, out notebookXml);
                var destinationDoc = XDocument.Parse(notebookXml);
                var destinationNs = destinationDoc.Root.Name.Namespace;
                var destinationPageSection = destinationDoc.Descendants(destinationNs + "Section").Where(n => n.Attribute("name").Value == "Lists").FirstOrDefault();
                var destinationPageNode = destinationPageSection.Descendants(destinationNs + "Page").Where(n => n.Attribute("name").Value == "Words").FirstOrDefault();
                if (destinationPageNode != null)
                {
                    var destinationPageId = destinationPageNode.Attribute("ID").Value;                
                    string destinationPageContent;
                    onApp.GetPageContent(destinationPageId, out destinationPageContent, PageInfo.piBasic);                
                }
            }
    
            public IStream GetImage(string imageName)
            {
                MemoryStream mem = new MemoryStream();
                Properties.Resources.HelloWorld.Save(mem, ImageFormat.Png);
                return new CCOMStreamWrapper(mem);
            }
        }
    }

    • Moved by CoolDadTx Friday, April 24, 2015 5:59 PM Office related
    Friday, April 24, 2015 5:01 PM

Answers

  • Hi JukeBox,

    According to the description, the Application.GetPageContent cost much time when the page is large and this operation will lead to the OneNote unresponsive.

    Based on my understanding, it is expected since the page is large. And the reaseon that for the OneNote application is unresponsive prevents users operating OneNote make the page content is not the latest.

    As a workaournd, we can copy the table into a spreadsheet and attach this file on OneNote to make the page is small.

    Hope it is helpful.

    Regards & Fei


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Wednesday, April 29, 2015 2:35 AM
    Moderator