.NET

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

Calling COM interop from another thread

292 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,398
Registered: ‎04-09-2008
Message 2 of 5 (273 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 (256 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,398
Registered: ‎04-09-2008
Message 4 of 5 (248 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 (233 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.

 

 

 

You are not logged in.

Log into access your profile, ask and answer questions, share ideas and more. Haven't signed up yet? Register

Announcements
Are you familiar with the Autodesk Expert Elites? The Expert Elite program is made up of customers that help other customers by sharing knowledge and exemplifying an engaging style of collaboration. To learn more, please visit our Expert Elite website.

Need installation help?

Start with some of our most frequented solutions to get help installing your software.

Ask the Community