.NET

.NET

Reply
Contributor
aligili
Posts: 11
Registered: ‎09-27-2012
Message 1 of 5 (345 Views)

Calling COM interop from another thread

345 Views, 4 Replies
03-13-2013 05:35 AM

Hi,

 

I have developoed a .Net dll(Autocad plugin) in which it tries to create a task on another thread.

The task lauches another instance of Autocad via COM interop and sends commands. But this throws exceptions at different points like SendCommand(...). 

I know .Net APIs are not multithread, but  here no .Net APIs are called in this new thread, and all COM object methods

are being called in the same thread(the newly created one) that the new Autocad instance is created(via COM).

 

Dose anyone know what the problem is ?

 

Many thanks

Moderator
Alexander.Rivilis
Posts: 1,458
Registered: ‎04-09-2008
Message 2 of 5 (326 Views)

Re: Calling COM interop from another thread

03-13-2013 08:41 AM in reply to: aligili

aligili wrote:

...The task lauches another instance of Autocad via COM interop and sends commands. But this throws exceptions at different points like SendCommand(...). ...


What exceptions are throwing?


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Contributor
aligili
Posts: 11
Registered: ‎09-27-2012
Message 3 of 5 (309 Views)

Re: Calling COM interop from another thread

03-13-2013 11:42 AM in reply to: Alexander.Rivilis

Thanks for your reply,

 

this exception is thrown :

the message filter indicated that the application is busy
HRESULT: (RPC_E_SERVICECALL_RETYLATER)

acAcadApp.BeginCommand += new _DAcadApplicationEvents_BeginCommandEventHandler(acSeperateApp_BeginCommand);
acAcadApp.EndCommand += new _DAcadApplicationEvents_EndCommandEventHandler(acSeperateApp_EndCommand);
acAcadApp.BeginOpen += new _DAcadApplicationEvents_BeginOpenEventHandler(acSeperateApp_BeginOpen);
acAcadApp.EndOpen += new _DAcadApplicationEvents_EndOpenEventHandler(acSeperateApp_EndOpen);

 

either at

-acAcadDoc.SendCommand(cmd);

or at the time of registering application events :

-AcadApplication acAcadApp = new AcadApplication();

if (acAcadApp == null) return false;

acAcadApp.BeginCommand += new _DAcadApplicationEvents_BeginCommandEventHandler(acSeperateApp_BeginCommand);
acAcadApp.EndCommand += new _DAcadApplicationEvents_EndCommandEventHandler(acSeperateApp_EndCommand);
acAcadApp.BeginOpen += new _DAcadApplicationEvents_BeginOpenEventHandler(acSeperateApp_BeginOpen);
acAcadApp.EndOpen += new _DAcadApplicationEvents_EndOpenEventHandler(acSeperateApp_EndOpen);

acAcadApp.Visible = false;

 

I also removed registering the events for the COM object but did not change anything.

 

Moderator
Alexander.Rivilis
Posts: 1,458
Registered: ‎04-09-2008
Message 4 of 5 (301 Views)

Re: Calling COM interop from another thread

03-13-2013 03:59 PM in reply to: aligili

aligili wrote:

Thanks for your reply,

 

this exception is thrown :

the message filter indicated that the application is busy
HRESULT: (RPC_E_SERVICECALL_RETYLATER)


Maybe RPC_E_SERVERCALL_RETRYLATER ?

Try this solution: http://through-the-interface.typepad.com/through_the_interface/2010/02/handling-com-calls-rejected-b...

 


Пожалуйста не забывайте про Утвердить в качестве решения! Утвердить в качестве решения и Give Kudos!Баллы
Please remember to Accept Solution! Accept as Solution and Give Kudos!Kudos

Contributor
aligili
Posts: 11
Registered: ‎09-27-2012
Message 5 of 5 (286 Views)

Re: Calling COM interop from another thread

03-14-2013 02:35 AM in reply to: Alexander.Rivilis

Thanks Alexander,

 

The class has already implemented the interface. but thanks for your reply.

 

 

 

Post to the Community

Have questions about Autodesk products? Ask the community.

New Post
Announcements
Do you have 60 seconds to spare? The Autodesk Community Team is revamping our site ranking system and we want your feedback! Please click here to launch the 5 question survey. As always your input is greatly appreciated.