Currently I work on an excel automatization project and I got stuck in the following problem.
Usually when I set a formula in a range, it takes time while excel calculating it.
So when the program start the next call I get this error message: 0x80010001 (RPC_E_CALL_REJECTED).
Firs I tried with sleep times, but it didn’t worked all time, because these calculating times, depends on a processor load etc.. so it is not deterministic.
After I use Application.Ready to check that is excel ready for next call.
I did it like this: (I put this function in the function, which I use to write a formula in a range):
//this is the waiter function
public static void waitForReady(Excel.Application app)
{
while (!app.Ready)
{
System.Threading.Thread.Sleep(1000);
}
}
//this is the range formula writer function
public static void setRangeFormula(Excel.Worksheet ws, int startRow, int startColumn, int endRow, int endColumn, string formula)
{
Excel.Range myRange = getRange(ws, startRow, startColumn, endRow, endColumn);
myRange.Formula = formula;
ExcelMethods.waitForReady(ws.Application); //i want to wait here until excel is ready, and return after
}
The problem is I get the error the line which contains the check:
while (!app.Ready)
Could you please help me how can I check the ready status without get this error?
I don’t understand whats the sense of Application.Ready, if i cannot use it when the app is not ready…