Parallelization of method calls to several VCProject instances

Unanswered Parallelization of method calls to several VCProject instances

  • Tuesday, August 07, 2012 7:22 AM
     
      Has Code

    Hello,

    I'm writing a stand alone application, which uses the VCProjectEngine of VS2010 to read *.vcxproj files and processes the information of them (e.g. additional include directories or configurations for files). I use C++/CLI and VS2010 Professional. This works very well, but seems to be slow, because of the processing of the project information by me. Therefore I decided to use parallelization to speed it up.

    I'm using the Parallel.ForEach loop, which calls the following method for every project path. In the ProcessProject method I access, evaluate and store the information of the project. The access to common data structures for storing the information is synchronized properly.

    void EvaluateProject(String^ projectPath)
    {
      VCProjectEngine^ projectEngine = gcnew VCProjectEngineShim();
      VCProject^ project = projectEngine->LoadProject(projectPath);
    
      ProcessProject(project);
    
      projectEngine->RemoveProject(project);
    

    Now I'm experiencing several problems. First of all parallel loading of the projects doesn't seem to work properly. I get a System.InvalidOperationException (Collection was modified; enumeration operation may not execute.) in Microsoft.VisualStudio.Project.VisualC.VCProjectEngine.dll. I don't know why this problem occurres, since i create a new instance of the VCProjectEngine for every project I want to read. Therefore there shouldn't be synchronization problems.

    Anyway I also tried to read all projects first and only process them in the Parallel.ForEach loop. Sadly this also results in several exceptions, which change every time I run the loop (as it is supposed to do due to nondeterministic threading). They occure in the assemblies of the VCProjectEngine, so i can't determine the cause of them. Some of the messages are about parameters, which are null, or entries, which are already in a dictonaries. I don't use a dictionary and no parameter is null. I think there might be some caching in the VCProjectEngine, which is not thread safe.

    The documentation contains very less information about thread safety, so i need your help on that topic. Is there a way to use VCProjectEngine and threading?

    Best regards

    PS: Since VCProjectEngine is used for extensions, I posted in the Extensibility section. If this is wrong, please move the post to the correct section.

All Replies

  • Wednesday, August 08, 2012 1:35 AM
    Moderator
     
     

    Hi John,

    We know only Visual C++ project model object that can be returned by CoCreateInstance. If we load other type project via VCProjectEngine, the exception will be reported.

    Are you sure the project you load is a C++ project?

    Best regards,


    Ego [MSFT]
    MSDN Community Support | Feedback to us

  • Wednesday, August 08, 2012 7:10 AM
     
     

    Hi Ego,

    thanks for your reply. When I try to load a non C++ project, I get a COMException. I'd already written a catch clause to handle it. I'm sorry for not including it in the example.

    Since I don't receive any exceptions when running the mentioned method in a regular loop, I assume that there is a problem with threading in VCProjectEngine and the associated classes.

    Therefore I think I need a way to create multiple instances of VCProjectEngine, which are separated from each other to avoid the threading problems or I have to get to know where I have to synchronize calls to the VCProjectEngine classes methods.

    Best regards

  • Wednesday, August 15, 2012 12:30 PM
     
     

    Hi,

    I think I forgot to post the question after the last part of my reply:

    Does somebody know a way to create multiple instances of VCProjectEngine or to synchronize calls to a single instance in order to avoid the mentioned problems with threading?

    Best regards