You could try subscribing to the ApplicationIntitialized
event - I bet that only gets fired when Revit is fully loaded.
From the documentation:
The event is raised after Revit was launched as fully initialized, including initialization of external applications.
So... In your OnStartup
method, do something like this:
public Result OnStartup(UIControlledApplication application)
{
Result result = CreateApplication(application);
if (result == Result.Succeeded)
{
application.Application.ApplicationInitialized += new EventHandler(delegate (Object o, ApplicationInitializedEventArgs a) {
// this code will be deferred until the application is initialized
UpdateService updates = new UpdateService();
try
{
updates.ManageUpdates(application);
}
catch (Exception ex)
{
NotificationManager.Notify("error", ex.InnerException.Message, messageType.error);
}
});
}
return result;
}
EDIT: I didn't notice that I was referring to the Revit 2013 API reference and missed that 2012 doesn't have an ApplicationInitialized
event. In this case, you could try to hook up to one of the DocumentOpening
or Idling
events, that will let you no that the application has initialized, but sadly at a moment when the user is just about to do something and that might make him mad.
It would be interesting to know if the Idling
event fires without a document open - this might solve your problem. Could you try that out and report back?