Document throws "InvalidObjectException" in Idling Event

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Hi guys,
I have a modeless dialog and I use Idling event to handle its evets. So the code goes like this
First the External Command:
Result MenuHandler::Execute(ExternalCommandData^ commandData, String^% message, ElementSet^ elements)
{
Transaction^ transaction = gcnew Transaction(commandData->Application->ActiveUIDocument->Document, "Menu Handler");
transaction->Start();
// Here I create a new Form and Show it
transaction->Commit();
return Result:: Succeeded;
} //MenuHandler::Execute
Then I queue events from the modeless dialog to be all handled when the Idling event is fired.
And the code for the IdleHandler is
System::Void FormsHandler:: onIdling(Object^ sender, IdlingEventArgs^ args)
{
UIApplication^ uiApplication = dynamic_cast<Autodesk::Revit::UI::UIApplication^>(sender);
if (uiApplication == nullptr)
return;
//This Next line throws 'Autodesk.Revit.Exceptions.InvalidObjectException' occurred in RevitAPI.dll
//Additional information: The managed object is not valid.
Transaction^ transaction = gcnew Transaction(uiApplication->ActiveUIDocument->Document, "Idle Handling");
transaction->Start();
//Here I handle each event in the queue and then empty the queue
transaction->Commit();
} //FormsHandler:: onIdling
Can anyone help with this, whenever I try to use the Document object it throws InvalidObjectException, I assume it has something to do with the transaction but I am not sure what. Am I missing something ?
Thank you