COM Interop - Wait for Excel to Complete Operation

Posted by roygbiv on Stack Overflow See other posts from Stack Overflow or by roygbiv
Published on 2010-04-06T15:24:11Z Indexed on 2010/04/06 16:33 UTC
Read the original article Hit count: 422

Filed under:
|
|
|

Hello,

I am doing some COM Interop work with Excel and other Office Automation Software.

A Co-Worker has mentioned to me that I need to wait for these Automation Servers to become ready after issuing a command to them.

I, however, cannot see the purpose of this as don't all calls block until the automation server completes the given task?

For example I would normally write:

Dim o as AutomationObject = AutomationServer.CreateObject(x, y, z)
o.Property ' could throw COM exception!!????

My co-worker says I need to sleep after that call because the the Automation Server could still be working on creating and initializing the object.

Dim o as AutomationObject = AutomationServer.CreateObject(x, y, z)
Threading.Sleep(5000) ' wait for AutomationServer to "become ready"
o.Property ' could still throw COM exception!!????

The problem I have with this is that the AutomationServer calls should block until the AutomationServer finishes or completes what it was working on or at the very least it should be a loop checking if "o" is nothing, but that makes no sense because once the call returns its done!

My question is, Is there any benefit to Sleeping after an AutomationServer call? Is there a method to "wait" until the AutomationServer finishes (if it does not in fact block)?

© Stack Overflow or respective owner

Related posts about com

Related posts about automation