Revit API Forum
Welcome to Autodesk’s Revit API Forums. Share your knowledge, ask questions, and explore popular Revit API topics.
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

[HELP] About committing transaction in Thread...

2 REPLIES 2
Reply
Message 1 of 3
cjwfy8871
977 Views, 2 Replies

[HELP] About committing transaction in Thread...

I'm developing an add-in on Revit2013, it involves using a thread to do some calculation and commit the changes back to the .rvt. Now the problem occurs:

When I use transaction in the main thread, namely the IExternalCommand one, it is totally ok; yet if I put the code inside a self created thread, the whole Revit would abort and exit ! 

Here's the code i put in a thread:

 

Thread t = new Thread(delegate()
{

   try
   {
       using (Transaction tras = new Transaction(commandData.Application.ActiveUIDocument.Document,"test"))
       {
        tras.Start();

        tras.Commit();
       }
   }
   catch (Exception e)
   {
      MessageBox.Show(e.Message);
   }

}

t.Start();

 

even the catch could not get the exception, the Revit just exit without exception report.

I really have no idea why Revit doesnt let me commit transaction inside other thread ( I have trace the error, it occur before the tras.Commit ). Anyone have any idea? Thanks ahead.

Tags (2)
2 REPLIES 2
Message 2 of 3
ollikat
in reply to: cjwfy8871

I'm sorry to tell you that the Revit API doesn't support calls from other threads. It's a simple as that 🙂

 

At least here you can find some more information:

 

http://thebuildingcoder.typepad.com/blog/2011/06/no-multithreading-in-revit.html

Message 3 of 3
saikat
in reply to: ollikat

Yes, your findings are correct.


The following post might also be helpful:

http://adndevblog.typepad.com/aec/2012/06/multi-threading-with-revit.html?asset_id=6a0167607c2431970...

 

cheers

Saikat

 



Saikat Bhattacharya
Senior Manager - Technology Consulting

Can't find what you're looking for? Ask the community or share your knowledge.

Post to forums  

Autodesk DevCon in Munich May 28-29th


Rail Community