-
it is possible to make excel call functions asynchronously? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Yes - you can make asynchronous functions with Excel-DNA.
|
Beta Was this translation helpful? Give feedback.
-
I don't think you can get the function wizard to work for async functions like that. The only way might be like this, to check when you are in the function wizard, and then to call the Task-returning function synchronously. But the user experience might not be great if your function is slow, as it will wait for the calculation result every time the change an argument in the dialog. public static object MyFunction(object arg1, object arg2)
{
if (ExcelDnaUtil.IsInFunctionWizard())
{
var functionTask = MyFunctionImplAsync(arg1, arg2);
return functionTask.Result;
}
else
{
var functionName = nameof(MyFunction);
var parameters = new object[] { arg1, arg2};
return AsyncTaskUtil.RunTask(functionName, parameters, () => MyFunctionImplAsync( arg1, arg2 ));
}
} |
Beta Was this translation helpful? Give feedback.
Yes - you can make asynchronous functions with Excel-DNA.
Best is to make your function as a normal .NET async function that returns Task. To glue this up with Excel you have a few options: