Ming Chao
Posts: 30
Joined: 2019-01-23
|
Hi,
my app makes an api call and when data return it will populate an excel range object with a 2D array data using range.Value2 property. sometimes the API call take a few seconds. if end user is selecting the cell without releasing the mouse button or in cell edit mode and the app populating the Range object at the same time then HRESULT 0x800AC472 exception will be thrown. this all seems to be caused by the object browser is suspended as described the quote below. the post from MSDN suggested to keep trying in a loop until succeed. seems this is not ideal to introduce some boilerplate codes. is there's a better way to handle this error?
you are getting the VBA_E_IGNORE error that Excel will return when you try to invoke the object model when the property browser is suspended. This will happen around user edits to ensure that things don't get out of whack with automation slipping in in the middle. What Excel is telling you is simply that it isn't ready to handle your call at the time you are making it.
https://social.msdn.microsoft.com/Forums/vstudio/en-US/ee0bdafa-6d6d-4025-b7cb-5537d79dbc48/writing-data-from-c-to-excel-interrupted-by-opening-excel-help-or-options-window?forum=csharpgeneral |
|
Andrei Smolin
Add-in Express team
Posts: 18830
Joined: 2006-05-11
|
|
Ming Chao
Posts: 30
Joined: 2019-01-23
|
Hi Andrei,
thank you for your reply. im able to resolve my issue by polling ExcelApp.Interactive in a do-while loop. im using a Task.Delay() inside a catch block to wait indefinitely. are there any side affects by doing so in the main thread. below is my code snippet of my implementation.
public async void writeData()
{
...
await SetInteractive(false);
range.Value2 = Get2DArray(); //2D array
await SetInteractive(true);
...
}
private async Task SetInteractive(bool interactive)
{
do
{
try
{
excelApp.Interactive = interactive;
}
catch (Exception e)
{
await Task.Delay(1000);
}
} while (excelApp.Interactive != interactive);
} |
|
Andrei Smolin
Add-in Express team
Posts: 18830
Joined: 2006-05-11
|
Hello Ming,
I would check how this construct behaves when you close Excel.
Andrei Smolin
Add-in Express Team Leader |
|
Ming Chao
Posts: 30
Joined: 2019-01-23
|
thank you Andrei. my code could cause excel process to hang after closing excel. we decided to let end user to handle the situation. |
|
Andrei Smolin
Add-in Express team
Posts: 18830
Joined: 2006-05-11
|
Welcome!
Andrei Smolin
Add-in Express Team Leader |
|