Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue when opening a new workbook during a function call #721

Open
jwilder123 opened this issue Sep 19, 2024 · 2 comments
Open

Issue when opening a new workbook during a function call #721

jwilder123 opened this issue Sep 19, 2024 · 2 comments

Comments

@jwilder123
Copy link

Steps to reproduce:

  1. =Test(TODAY())
  2. Click Enter
  3. Within the 1 second wait, click Ctrl + N to launch a new workbook

The results will not be returned. Furthermore, any calls on new workbooks to '=Test(TODAY())' will immediately return 'Hello' (ie: not recalling the function, simply returning the cached result)

`
using ExcelDna.Integration;
using ExcelDna.Registration;

namespace DNABug
{
public class Class1
{
public partial class Registration : IExcelAddIn
{
public void AutoOpen() => ExcelRegistration.GetExcelFunctions().ProcessAsyncRegistrations().RegisterFunctions();
public void AutoClose() { }

        [ExcelFunction(Name = "Test")]
        public static async Task<Object> Tester([ExcelArgument(Name = "p1")] object p1)
        {
            await Task.Delay(1000);
            return "Hello";
        }
    }
}

}
`

@govert
Copy link
Member

govert commented Sep 21, 2024

Calling RTD-based async functions with volatile inputs is a problem, and I don't have a good 'default' solution for this yet.

Some options:

  • Make your own "TODAY.NV()" function that is not volatile.
  • Cache the async result for a short time (a few seconds or minutes) and return directly from the cache. This would need some re-engineering of the function instead of using the default Task-processing.

It's certainly a problem and needs more thought but is a consequence of the Excel-DNA approach to implementing async functions. Not simple . . .

@jwilder123
Copy link
Author

jwilder123 commented Sep 21, 2024

Thanks so much! And thanks for all your efforts on this project! Any chance you can point me to an example of the second approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants