Speed up the selection and creation of tasks in Project 2013 using VSTO RRS feed

  • Question

  • I have written a VSTO application for project 2013 and am happy with its functionality, however the speed inserting new tasks, and the complexity of selecting tasks in the view is becoming a bottleneck.  I hope I'm doing something wrong that is easily fixed, if anyone can help ?

    1) Slow to insert new tasks - if the project has about 5000 tasks or so, inserting takes about 1 second per task, whereas doing the same operation manually, using the gui as a user, is fast enough to not be noticeable.  What can I do to speed up this process ?  setting ScreenUpdating to false during this process has no effect.  This is the code to create tasks:

    var newTask = _project.ActiveProject.Tasks.Add(taskName, insertionIndex);

    2) complex to select tasks in view - if I know a task, or a task ID, AND the project has outline tasks that are folded, then selecting a task is no longer a matter of pulling out its ID.  Currently I have to work out its visual index by counting all the way from the end task.  This feels so wrong.  Please tell me there is a way to interact with tasks, in reference to their visual position only ?  

    Ideally, if I had a task object, I would like to be able to then select that task programmatically, REGARDLESS of any folded outline tasks.

    Any help appreciated.

    Monday, June 15, 2015 12:24 PM

All replies

  • bitbandit2 --

    To speed us the execution of macros that I have written in Microsoft Project VBA, I have disabled automatic calculation at the beginning of the code and then re-enabled automatic calculation at the end of the code.  This had a dramatic effect on the execution speed.  Just a thought.  Hope this helps.

    Dale A. Howard [MVP]

    Monday, June 15, 2015 1:25 PM
  • bitbandit2,

    Dale's suggestion about turning off auto-calculate during execution of VBA code is a good one. I do that frequently with macros I write.

    With regard to speed of execution of VBA code in general. There are two basic ways of accessing data, foreground processing and background processing. Any operation that operates on data in the view (i.e. ActiveSelection.Tasks), will generally always be slower that operating on data directly in Project's underlying database (i.e. ActiveProject.Tasks). Most operations that need to be done can use background processing which is independent of the active view, however there are some instances where the operation can only be done effectively by selecting the desired field cell shown on the current view. So when you say, "if I had a task object, I would like to be able to then select that task programmatically", you can do that. For example, let's say you know that task you need to operate on is task ID 15, you can refer to it using the following, whether that task is shown on the current view or not.


    However, keep in mind that task IDs can change, so it is better to use the task Unique ID field. In that case the syntax would be:

    ActiveProject.Tasks.UniqueID(x)     'where "x" is the Unique ID of the desired task.

    However, if I'm writing code that needs to operate on the whole project, I'll use the common structure

    Dim t as Task

    For Each t in ActiveProject.Tasks

    [code to do whatever]

    Next t

    In some cases, I might only want to operate on a very select set of tasks in the file, for example on a filtered set of tasks. Then I'll use the following:

    Dim t as Task


    For Each t in ActiveSelection.Tasks

    [code to do whatever]

    Next t

    In some cases the latter may actually execute faster than the former even though it is operating in foreground mode, but, it is faster because it is operating on a very limited set of data in the whole file.

    Hope this helps.


    Monday, June 15, 2015 2:57 PM
  • Okay, your big problem with a VSTO add-in is that it runs in a separate Windows process. This means every action incurs an inter-process overhead. Because of this Project VBA (which runs inside the Project process) runs faster than compiled add-ins when reading and writing data.

    I wrote a quick bit of VBA to create 5000 tasks in a new schedule. I then timed adding 10 extra tasks with VBA, to the end of the project and it took .32 seconds (for 10 tasks).

    I would expect a VSTO add-in to take seconds to do the same thing so most of your time is explained by the above.

    For selecting tasks by moving the cursor, they have to be visible. That has always been true. However as John has explained you can manipulate task objects etc in the background without having to have them visible. This is the best way by far and is significantly faster.

    Rod Gill
    Author of the one and only Project VBA Book

    Monday, June 15, 2015 9:28 PM
  • Well at least I can say that disabling ScreenUpdating also doesn't work:

    Tuesday, November 13, 2018 7:46 PM
  • Dear Rod, I admire your book. It's the only source that helps. Now, I tried to advance to VSTO, I'm totally angry about the performance. BTW: it's the same issue when you try to add resources. Adding 100 resources takes 26s. Incredibly slow. Using your advice (switching to another view) certainly helps and drops it down to 7s. On 8GB 8core systems this is still unacceptable.


    • Edited by rudisoft Tuesday, November 13, 2018 7:59 PM
    Tuesday, November 13, 2018 7:51 PM