is there a better way to handle RPC_E_CALL_REJECTED exceptions when doing visual studio automation?

后端 未结 4 552
傲寒
傲寒 2021-01-01 03:48

this is what I\'m currently doing:

    protected void setupProject()
    {
        bool lbDone = false;
        int liCount = 0;
        while (!lbDone &         


        
4条回答
  •  天命终不由人
    2021-01-01 04:08

    First, Hans doesn't want to say so but the best answer to "how to do this" is "don't do this". Just use separate instances of visual studio for your automation and your other work, if at all possible.

    You need to take your problem statement out somewhere you can handle the error. You can do this by using in integer index instead of foreach.

    // You might also need try/catch for this!
    int cProjectItems = pProject.ProjectItems.Length;
    for(iProjectItem = 0; iProjectItem < cProjectItems; iProjectItem++)
    {
       bool bSucceeded = false;
       while(!bSucceeded)
       {
            try{
                ProjectItem pi = pProject.ProjectItems[iProjectItem];
                // do something with pi
                bSucceeded = true;
            }catch (System.Runtime.InteropServices.COMException loE)
            {
                liCount++;
                if ((uint)loE.ErrorCode == 0x80010001)                      {
                    // RPC_E_CALL_REJECTED - sleep half sec then try again
                    System.Threading.Thread.Sleep(pDelayBetweenRetry);
                }
            }  
       }
    
    }
    

提交回复
热议问题