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.
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
Yes, your findings are correct.
The following post might also be helpful:
cheers
Saikat