Error: setValue on engaged ControlledLocalPointer before existence of TaskBlock

Error: setValue on engaged ControlledLocalPointer before existence of TaskBlock

Anonymous
Not applicable
621 Views
5 Replies
Message 1 of 6

Error: setValue on engaged ControlledLocalPointer before existence of TaskBlock

Anonymous
Not applicable

i'm writing a program that uses threading. At the moment i'm running into a problem. 

On my first thread i'm able to use the doc.EditFamily command. On my second thread it seems i may not use this command. 

 

I keep getting this error in my script: 

setValue on engaged ControlledLocalPointer before existence of TaskBlock: line 90 of Tasks

 

line 90 of my script reads: 

famDoc = doc.EditFamily( f.Symbol.Family ) 

 

in addition when i try to use the LookupParameter method i get this error:

getElement is only allowed to run in multi-threaded scope

 

I've tried calling this command in different ways but every time it it seems to me i'm not allowed to edit a family in multiple threads. 

How can i solve this? 

 

 

0 Likes
Accepted solutions (1)
622 Views
5 Replies
Replies (5)
Message 2 of 6

Anonymous
Not applicable

the Revit API only supports single-threaded access I'm affraid...

0 Likes
Message 3 of 6

Anonymous
Not applicable

Thankyou for your reply Scott, 

 

Are you absolutely sure of this? Except for using famDoc my program works just fine. On my second thread i can still use f.Symbol.FamilyName and other methods.  

 

 

This brings up a new question for me then; How can i open multiple WindowsForms without multithreading? 

On __init__() my program starts up a class Form(). 

        One of the buttons on this form causes a new class Form2() to open up. 

        As far as i know this option needs to run on a second thread. Can a single thread program run 2 windows simultaniously? 

 

Is there a workaround for this program? Surely Revit uses multithreading in for instance the material editor ( a button opens a new form, in the new form a button opens another form)

 

0 Likes
Message 4 of 6

Anonymous
Not applicable
Accepted solution
I'm no expert on this, but this topic comes up pretty frequently and the answer is always "not supported". You may get some functionality to work but it will be hit and miss on the reliability. The offical word is that it isn't supported to access the API from multiple threads. You could probably still make use of multiple threads in your application but you'll need to fall back to the main thread using thread-locked delegates, idling event callbacks or similar to reliably communicate with the API.
0 Likes
Message 5 of 6

Anonymous
Not applicable
What I do for using multiple forms is to keep all API specific code away from my Forms code.
0 Likes
Message 6 of 6

Anonymous
Not applicable

Thanks Scott, 

 

It's unfortunate that threading isn't supported. Meanwhile i'm happy that i found a workaround to my problem and i got my program to work. 

From now on this just has to be something to keep in mind. 

0 Likes