有没有更好的方法做的Visual Studio自动化时处理RPC_E_CALL_REJECTED异常? [英] is there a better way to handle RPC_E_CALL_REJECTED exceptions when doing visual studio automation?

查看:406
本文介绍了有没有更好的方法做的Visual Studio自动化时处理RPC_E_CALL_REJECTED异常?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我目前做的:

    protected void setupProject()
    {
        bool lbDone = false;
        int liCount = 0;
        while (!lbDone && liCount < pMaxRetries)
        {
            try
            {
                pProject.ProjectItems.Item("Class1.cs").Delete();
                lbDone = 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);
                }
            }
        }
    }

现在我有一个try catch块各地的大多数调用到EnvDTE东西,和它的作品不够好。我的问题是,当我通过一个集合并做一些事来每个项目一次。

now I have that try catch block around most calls to the EnvDTE stuff, and it works well enough. The problem I have is when I to loop through a collection and do something to each item once.

foreach(ProjectItem pi in pProject.ProjectItems)
{
    // do something to pi
}

有时我在的foreach例外(以pProject.ProjectItems项目项PI)行。
因为我不想启动foreach循环结束,如果我得到的RPC_E_CALL_REJECTED例外,我不知道我能做些什么。

Sometimes I get the exception in the foreach(ProjectItem pi in pProject.ProjectItems) line. Since I don't want to start the foreach loop over if I get the RPC_E_CALL_REJECTED exception I'm not sure what I can do.

编辑回答评论:
是的,我从另一个程序自动化VS是的,我通常使用VS用于在同一时间别的东西我。我们有读取XML文件,然后根据XML文件约50 VS解决方案的应用程序。这通常需要几个小时,所以我尝试这样做,而这种情况正在发生的其他工作。

Edit to answer comment: Yes I'm automating VS from another program and yes I usually am using VS for something else at the same time. We have an application that reads an xml file then generates around 50 VS solutions based on the xml file. This usually takes a couple of hours so I try to do other work while this is happening.

推荐答案

首先,汉斯不要这么说,但最好的回答如何做到这一点就是不这样做。只需使用Visual Studio的不同实例为您的自动化和您的其他工作的如果在所有可能的

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.

您需要把你的问题陈述了什么地方可以处理错误。您可以通过使用整数指数代替的foreach做到这一点。

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);
            }
        }  
   }

}

这篇关于有没有更好的方法做的Visual Studio自动化时处理RPC_E_CALL_REJECTED异常?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆