.NET
cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

.Net API and Multi-Thread

3 REPLIES 3
SOLVED
Reply
Message 1 of 4
JASONBIRD
3096 Views, 3 Replies

.Net API and Multi-Thread

I am developing a .Net (windows form) application which will be called by a command from autocad.
The task is looking through all entities in the model and select specific polygons. This is sort of a heavy task, so I am having the UI freezed for minutes which is not suitable. Thus I tried run the task in seperate thread: starting a transaction, getting objects and check some of their properties.
Now, it works fine with one transaction , but if I use more than one transaction the app fails randomly. The stack shows error on this call:

".. Autodesk.AutoCAD.Runtime.Interop.CheckNull(IntPtr returnValue)
   at Autodesk.AutoCAD.ApplicationServices.TransactionManager.StartTransaction()"

or when Autocad tries to Dispose the transaction object. ( I'm using USING block for strating transaction, therefore not calling Dispose method in the code.)

but these error never happenes in single-thread mode.

Can you please help  me to understand the reason and find a solution ?
Or what else can one do to make UI responsive when a time-consuming task is running?

Thanks,
ali

3 REPLIES 3
Message 2 of 4
chiefbraincloud
in reply to: JASONBIRD

Calls into the AutoCAD .NET API from a separate thread are not safe, as you have discovered.

 

As far as the UI, check out these posts on Through The Interface:

 

http://through-the-interface.typepad.com/through_the_interface/2007/02/allowing_users_.html

http://through-the-interface.typepad.com/through_the_interface/2007/05/displaying_a_pr.html

http://through-the-interface.typepad.com/through_the_interface/2007/08/a-handy-net-cla.html

 

I think that the third link is pretty much a combination of the first two, but it has been a while since I read them, so I gave all three, just in case there were differences in the approach.

Dave O.                                                                  Sig-Logos32.png
Message 3 of 4
dgorsman
in reply to: JASONBIRD

Are you running the calculations as you iterate through the objects?  If so, consider harvesting the data from the objects in the drawing in a very lightweight loop (minimal filtering) and then passing the raw data into your calculations.  You may be able to successfully spin off those calculations into multiple threads since they would not be dependant on AutoCAD.

 

Oh, hang on - just re-read your post.  Calling a separate UI-based application outside of AutoCAD will cause all sorts of slowness.  If at all possible, keep everything in-house to maximize speed.  Trying to run drawing-dependant calculations outside of AutoCAD while the user can diddle inside the drawing can be *very* problematic as well.  Very few professionally developed applications do this, and for good reason.

----------------------------------
If you are going to fly by the seat of your pants, expect friction burns.
"I don't know" is the beginning of knowledge, not the end.


Message 4 of 4
JASONBIRD
in reply to: chiefbraincloud

Many thanks guys,

I used the DoEvents method and its working fine.

 

Why dose it make faster if the application run the code inside autocad rather than windows-form app?

 

thnx

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


Autodesk Design & Make Report

”Boost