Hi,
Excel freezes sometimes after having used the UDFs in the Addin.
My issue is similar to the issue mentioned in this post https://groups.google.com/forum/#!topic/exceldna/MUw98OI2GcY
I am not able to reproduce the issue by locking my screen when an Excel instance is running my ExcelDna add-in as described inAny update on this issue? If anyone faced this issue in version 0.30 please advise.
Other details.
In my Addin I have used Excel-DNA version 0.30 .
I have couple of methods with signature
[ExcelFunction(IsHidden = false, IsThreadSafe = true)]
public static object method1(string inputfield1, string inputfield1)
where I return a single value(string or integer)
and a method with signature
[ExcelFunction(IsHidden = false)]
public static object method2(string securityIdentifier, object requiredfields)
where I return a array.
Multithreading is allowed for method1 and not for method2.
In method1 i do not try to access ExcelDnaUtil.Application inside the UDF which can cause exception since multi-thread calculation is allowed.
Instead I queue the task using ExcelAsyncUtil.QueueAsMacro(MyMacro) and in the macro MyMacro use ExcelDnaUtil.Application to update the statusbar.
In method2 I access the ExcelDnaUtil.Application inside the UDF as it is allowed since it is not marked as threadsafe.
I have a ribbon button through which i force recalculation for all the formulas in the sheet.
Apart from this i use
ExcelReference caller = XlCall.Excel(XlCall.xlfCaller) as ExcelReference;
I am not sure if I am doing something wrong that is causing excel to freeze or whether it is still a bug in Excel DNA version I am using.
Please let me know if any ideas.
Thanks in Advance,
Hi Govert,
In my Addin I use the ExcelAsyncUtil.QueueAsMacro to run the code in a macro context and use the COM API as you have suggested below. I do not access the COM API in any other way apart from this.
“I'd suggest you either replace the COM API calls in your UDF with calls to the C API, or use the ExcelAsyncUtil.QueueAsMacro to run the code in a macro context where use of the COM API is supported. Sadly, the Excel team has not made all features of the COM API are available via the C API, so we're sometimes a bit stuck since the async macro will only run after the calculation completes.”
The issue I get sometimes(Not easily reproducible.The excel freezes : Not able to select a cell in the sheet, cursor appears as + , happens when the sheet is kept open for a longer duration ) is that Excel does not respond
after having used the udfs in the Addin.
There is no exception thrown or any error notification when this issue occurs.
Please let me know if I can find the reason why this issue occurs.
Regards,
Arjun
Hi Govert,
Sorry for confusing you by saying that i am accessing COM API only through ExcelAsyncUtil.QueueAsMacro as in method1.
Basically UDFs of type method2 is not as frequently used in testing as UDFs of type method1 and
the Excel freeze issue was noticed after having used the UDFs of type method1.
I have now modified the add-in(removed calls to COM Api in method2) from my initial post as per your suggestion. I am continuing to test the addin to see if the issue still exists.
Since the issue was not easily reproducible at the first place , i will be testing it further.
I would like to replace two of the COM API calls with calls to the C API.
Please do let me know if you know how the below can be achieved by making calls to the C API.
_excelApplication = (Microsoft.Office.Interop.Excel.Application)ExcelDnaUtil.Application;
_excelApplication.ActiveWorkbook.Application.Cursor = Microsoft.Office.Interop.Excel.XlMousePointer.xlWait;
_excelApplication.StatusBar = "Requesting data...";
Thanks,
Arjun
Hi Govert,
I faced Excel freeze issue recently with 2 different scenarios and both these issues where resolved by adding IsMacrotType=true flag to the function.
Scenarios
a. Close all Internet Explorer windows.
b. Open up Excel and type in any formula. The formula makes a webrequest and fetches the data.
c. Open a IE window and open any website and then after 4 -5 seconds click the opened excel instance.
d. Excel will freeze.
This issue does not happens on all the test machines (happens in 2 machines out of 4 machines) but happens consistently in the machines in which this issue occurs.
By trail and error, i found that after adding IsMacrotType=true flag to the function this issue gets resolved :)
Would like to know why this issue happens in some machines but not in other . Also would like to know what the flag IsMacroType is meant for ?
Regards,
Arjun
Registering Worksheet Functions as Macro Sheet Equivalents (Handling Uncalculated Cells)
Placing a # character after the last parameter code in pxTypeText gives the function the same calling permissions as functions on a macro sheet. These are as follows:
- The function can retrieve the values of cells that have not yet been calculated in this recalculation cycle.
- The function can call any of the XLM information (Class 2) functions, for example, xlfGetCell.
- If the number sign (#) is not present: evaluating an uncalculated cell results in an xlretUncalced error, and the current function is called again once the cell has been calculated; calling any XLM information function other than xlfCaller results in an xlretInvXlfn error.
a. Close all Internet Explorer windows.
b. Open up Excel and type in any formula. The formula makes a webrequest and fetches the data.
c. Open a IE window and open any website and then after 4 -5 seconds click the opened excel instance.
d. Excel will freeze.