Hi
I'm trying to call ExcelAsyncUtil.QueueAsMacro from Excel AddIn. Using ExcelDna 34.6, tried on 33.9 also
Some pseudocode:
public void AutoOpen()
{
//Some calls to ExcelIntegration.GetRegistrationInfo, ExcelIntegration.RegisterUnhandledExceptionHandler
var externalComponent = new ExternalComponent();
externalComponent.OnComplete += OnCompleteOnDifferentThread;
}
public void OnCompleteOnDifferentThread()
{
ExcelAsyncUtil.QueueAsMacro(() =>
{
ExcelIntegration.RegisterXLL(_path);
});
}
On ExcelAsyncUtil.QueueAsMacro I get "Error (InvalidOperationException) trying to run SyncMacro - Excel is shutting down. Queued macro execution abandoned."
I suspect that it's some timing/initialization issue as
This also doesn't work (writes same "Error (InvalidOperationException) trying..."):
public void AutoOpen()
{
ExcelAsyncUtil.QueueAsMacro(() =>
{
MessageBox.Show("Test");
});
}
Following works
public void AutoOpen()
{
ThreadPool.QueueUserWorkItem(_ =>
{
Thread.Sleep(10000);
ExcelAsyncUtil.QueueAsMacro(() =>
{
MessageBox.Show("Test");
});
}, null);
}
Have anyone experienced/solved anything similar ?