Hi
We recently ported the majority of our functions to use the ExcelAsyncFunction attribute, which gives us far superior performance and user experience.
There is one edge case, however:
If we have an ExcelAsyncFunction (or synchronous ExcelFunction) which has, downstream somewhere, a call which does GetAwaiter().GetResult(), then Excel hangs for a few minutes, before returning the "Microsoft Excel is waiting for another application to complete an OLE action" popup.
On clicking "Cancel", the exception is
System.Runtime.InteropServices.COMException (0x80004005): Unspecified error (0x80004005 (E_FAIL))
at System.Threading.Monitor.ObjWait(Int32 millisecondsTimeout, Object obj)
at System.Threading.Monitor.Wait(Object obj, Int32 millisecondsTimeout)
at System.Threading.ManualResetEventSlim.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.SpinThenBlockingWait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at System.Threading.Tasks.Task.InternalWaitCore(Int32 millisecondsTimeout, CancellationToken cancellationToken)
at *.*.ProofOfHang()
Code to reproduce:
[ExcelAsyncFunction]
public static async Task<string> ProofOfHang()
{
AsyncTask().GetAwaiter().GetResult();
return "bob";
}
internal static async Task AsyncTask()
{
await Task.Delay(5000);
}
[ExcelFunction]
public static string ProofOfHang2()
{
AsyncTask().GetAwaiter().GetResult();
return "bob";
}
Both ProofOfHang and ProofOfHang2 "hang".
We register our async functions at addin load:
ExcelRegistration
.GetExcelFunctions()
.ProcessAsyncRegistrations(nativeAsyncIfAvailable: false)
In our case, we cannot, at this stage, untangle the downstream code to provide a "pure" async path.
We are using v1.7.0
Thanks
Graeme