我使用以下代码成功实例化/自动化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秒,是否有办法轮询此对象是否准备就绪?