Hi Brian,
Thank you for the detailed write-up and steps to reproduce this issue.
I’ve had a look, and I can reproduce the behaviour your describe with my Excel version 16.0.12607.20000 (32-bit) and Excel-DNA v 1.0.
Have you found that the behaviour, once broken, ever recovers for the Excel session?
The main source of information about thread-safe functions in .xll add-ins is this page:
https://docs.microsoft.com/en-us/office/client-developer/excel/multithreaded-recalculation-in-excel
My expectations according to this were:
I can recreate the problem you report with each of the three functions (with the thread-safe version of RANGE_VAL).
I should add an extra piece of information about Excel-DNA that might not be obvious. When converting a passed in reference to an ExcelReference structure, there might be extra calls by Excel-DNA to determine the correct sheet for the reference (depending on whether a local “SReference” or a global reference is passed). This means there are internal calls to xlfCaller, xlSheetNm and xlSheetId for an AllowReference function. While the Microsoft document says xlSheetNm and xlSheetId are thread-safe, the status of xlfCaller is not made explicit, though I would expect it to be fine for thread-safe functions.
Then I tried some initial tests:
Then the problem does not occur (of course now the reference passed in to the function is broken).
(The xlfCaller call is only there to work around an Excel bug where for IsMacroType functions xlSheetNm would incorrectly report the active sheet instead of the current sheet.)
The problem does occur in this case.
[ExcelFunction(IsThreadSafe = true)]
public static object GetSheetName()
{
var emptyRef = new ExcelReference(0, 0, 0, 0, IntPtr.Zero);
return XlCall.Excel(XlCall.xlSheetNm, emptyRef);
}
This reproduces the issue too, though no AllowReference is involved anymore.
The documentation clearly indicates that xlSheetNm is thread-safe, so this should be fine.
So either there is a bug in Excel, or something in the way Excel-DNA handling the memory in this case.
I would like to see if the problem can be recreated with a native code C add-in.
If the problem still occurs in this simpler case, then we can report to Microsoft.
I’m not sure when I’ll get a chance to look at it more, but that’s a start.
-Govert
--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/6dd0125d-4e72-4407-a836-70a1d260dbc8%40googlegroups.com.
Thanks Charles.
Yes, I think that the problem is exhibit with the AllowReference / “U” type in Excel-DNA is a red herring.
It looks like calling either xlSheetId or xlSheetNm inside a thread-safe function causes the problem
Both of these are explicitly called out as thread-safe in the official documentation.
-Govert
From: exce...@googlegroups.com <exce...@googlegroups.com> On Behalf Of FastExcel
Sent: 18 February 2020 18:15
To: Excel-DNA <exce...@googlegroups.com>
--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/94bccddd-d7b6-40f6-9ed2-205053aa54a2%40googlegroups.com.
Thank you Charles – that would be a big help!
I don’t have an easy way to check older Excel versions to see when this might have gone wrong.
We also don’t really know what other misbehaviour this state exhibits – maybe Brian can add what he’s found.
The array-change dialog not showing seems like an indication of the internal state of Excel being really weird.
xlSheetNm / xlSheetId are certainly functions that are useful from thread-safe functions.
I also see that xlfRtd is thread-safe in current versions, so Microsoft has made some improvements in that general area.
-Govert
--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exceldna+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/exceldna/94aaeeef-826e-4c3f-958e-09e27b450c42%40googlegroups.com.
Thank you Charles – that would be a big help!
I don’t have an easy way to check older Excel versions to see when this might have gone wrong.
We also don’t really know what other misbehaviour this state exhibits – maybe Brian can add what he’s found.
The array-change dialog not showing seems like an indication of the internal state of Excel being really weird.
xlSheetNm / xlSheetId are certainly functions that are useful from thread-safe functions.
I also see that xlfRtd is thread-safe in current versions, so Microsoft has made some improvements in that general area.
-Govert
From: exce...@googlegroups.com <exce...@googlegroups.com> On Behalf Of FastExcel
Sent: 19 February 2020 14:04
To: Excel-DNA <exce...@googlegroups.com>
Subject: Re: [ExcelDna] Re: Confirming limits of IsThreadSafe = true
I will see if I can get MSoft to do anything about it ... but I don't know if its a bug in the documentation or the XLL SDK ... and I doubt it would be high up the list of priorities!
--
You received this message because you are subscribed to the Google Groups "Excel-DNA" group.
To unsubscribe from this group and stop receiving emails from it, send an email to exce...@googlegroups.com.