Word 2007 add-in asynchronous operation RRS feed

  • General discussion

  • Hello,

    I am trying to create a Word add-in (Word 2007, VS 2008) to get various statistics for long texts. The functions for computing statistics are in a separate class and are not complicated, but are time-consuming. The calculations are started from a custom task pane button in my add-in and presented in a DataGridView control in the same CTP when finished. This works well, except that Word is blocked while the calculations are performed. For long texts this can take time (for example ~ 10 seconds for 800 hundred pages document). I have read some previous threads on this issue and attempted to use BackgroundWorker, but this didn't help - Word is stil blocked. Here is my current code:


         private void btnAnalyze_Click(object sender, EventArgs e)
        private void worker_DoWork(object sender, DoWorkEventArgs e)
          e.Result = Tools.CalculateStatistics(
        private void worker_RunWorkerCompleted(
          object sender, RunWorkerCompletedEventArgs e)
            new GridDelegate(RefreshGrid),
            e.Result as List<Tools.StatResults>);
        private void RefreshGrid(List<Tools.StatResults> list)
          statList = list;
          gridResults.DataSource = statList;

    I have posted this question on StackOverflow and they pointed me to a thread in this forum (here). I am not experiencing Word crashing like the OP from that thread, but I am attempting to use BackgroundWorker to update the DataGridView control in my Word CTP. So, my question is, how can I call a method asynchronously, so it doesn't block Word while executing?


    Uros Calakovic
    Thursday, April 21, 2011 1:46 PM

All replies