.NET

.NET

Reply
Contributor
11 Posts
0 Kudos
Registered: ‎09-27-2012
Post 1 of 5

Calling COM interop from another thread

355 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
1,465 Posts
277 Kudos
Registered: ‎04-09-2008
Post 2 of 5

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
11 Posts
0 Kudos
Registered: ‎09-27-2012
Post 3 of 5

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
1,465 Posts
277 Kudos
Registered: ‎04-09-2008
Post 4 of 5

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
11 Posts
0 Kudos
Registered: ‎09-27-2012
Post 5 of 5

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