How to check if excel is busy

Add-in Express™ Support Service
That's what is more important than anything else

How to check if excel is busy
 
Ashim Mishra




Posts: 43
Joined: 2016-03-01
Hi Team,

I want to know if there are any provision to check if excel is busy. I have been getting COMException while doing ExcelApp.Calculate most of the time. If there are any ways to check if Excel is busy then i can add that condition in that code block.

I know in COM we have IMessageFilter interface by implementing it, gives the RetryRejected way to make the COM call again. Is there something similar we can do with addinexpress ? It would be great if you can share some code example for the same.
Posted 14 Sep, 2020 02:57:37 Top
Andrei Smolin


Add-in Express team


Posts: 17361
Joined: 2006-05-11
Hello Ashim,

I suppose you get that exception because you perform COM calls in a thread other than the main one. Can this be the case? For instance, changing Ribbon controls is possible on the main thread only because internally, such a call invokes the IRibbonUI COM interface from the Office object model.

Ashim Mishra writes:
in COM we have IMessageFilter interface by implementing it, gives the RetryRejected way to make the COM call again


Although this is possible in theory, I've never seen this implemented in a VB/C# add-in.

Add-in Express doesn't provide such a way either. How could it provide such a way? We recommend using this approach: all COM calls should be performed on the main thread.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 14 Sep, 2020 03:50:41 Top
Ashim Mishra




Posts: 43
Joined: 2016-03-01
Hi Andrei,

We always make COM calls using the SendMessage mechanism, which i believe ensure that the interaction is happening on Main thread, isn't it ? Despite that it's throwing COMException.


Any thing else you can suggest to mitigate this issue ?
Posted 14 Sep, 2020 04:23:22 Top
Andrei Smolin


Add-in Express team


Posts: 17361
Joined: 2006-05-11
Hello Ashim,

The SendMessage()/OnSendMessage mechanism allows handling a message on the main thread (the message can be sent form any other thread). In what scenario(s) do you get the COM exception? Can it be that the user edits the cell when you get the exception? If so, check https://www.add-in-express.com/creating-addins-blog/2011/03/23/excel-check-user-edit-cell/.

Regards from Belarus (GMT+3),

Andrei Smolin
Add-in Express Team Leader
Posted 14 Sep, 2020 04:29:03 Top