相关疑难解决方法(0)

使用EnvDTE自动化Visual Studio

我使用以下代码成功实例化/自动化Visual Studio:

System.Type t = System.Type.GetTypeFromProgID("VisualStudio.DTE.9.0");
object obj = Activator.CreateInstance(t, true);
dte = (DTE)obj;
Solution sln = dte.Solution;
sln.Open(SolutionFile);
System.Threading.Thread.Sleep(1000);
//Do stuff with the solution
Run Code Online (Sandbox Code Playgroud)

注意Thread.Sleep(1000)电话?如果我不包含它,代码会在它准备好之前尝试对实例进行错误处理,并且我得到一个异常:

the message filter indicated that the application is busy.
Run Code Online (Sandbox Code Playgroud)

而不是等待n秒,是否有办法轮询此对象是否准备就绪?

c# automation visual-studio

30
推荐指数
2
解决办法
1万
查看次数

标签 统计

automation ×1

c# ×1

visual-studio ×1