getPageContent method takes 10 - 15 seconds to run

Hi,

I'm writing a OneNote 2010 Add-In using C#, 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);
        }
    }
}



  • Edited by Jukebox56 Friday, April 17, 2015 5:35 PM
April 17th, 2015 5:33pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics