I am successfully instantiating/automating Visual Studio using the following code:
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
Notice the Thread.Sleep(1000) call? If I don’t include that, the code tries to bug the instance before it’s ready and I get an exception:
the message filter indicated that the application is busy.
Rather than wait exactly n seconds, is there a way to poll this object for readiness?
As a solution to this issue you can register to an event that notifies when the solution load is done.
This is a sample of class that lets you listen to events on solution loading:
Usage example: