Excel-DNA/Samples

What are the 1st and 2nd arguments in ExcelAsyncUtil.Run for?

Jennal opened this issue · 2 comments

In AsyncHelloWorld, there is one line code like

ExcelAsyncUtil.Run("RunSomethingDelay", new [] { name }, () => RunSomethingDelay(name));

And I replace the 1st and 2nd arguments into this, and nothing changed.

ExcelAsyncUtil.Run("aaa", null, () => RunSomethingDelay(name));

So, what are the 1st and 2nd arguments in ExcelAsyncUtil.Run for?

The first two arguments are combined to make a unique identifier for the call.
When the async task completes, Excel-DNA internally stores the result, and notified Excel to refresh the cell. The function is then re-evaluated, and the unique identifier used to find the matching result to return.

If you don't create a unique identifier from the call that uses the function arguments, multiple calls that are running at the same time cannot be distinguished, and everything will go wrong.

The recommended practice is to pass in a unique identifier for the function (like the name) and all the function parameters (in this case the 'name' parameter).

If you just make a single call or have a single async task running at a time, as you tried, you won't see the problem.

Thank you for your kindly reply, very very clear! I got it now.