Hi,
I have recently upgraded from 0.65 to 0.73 and while I have seen some performance improvements, several reports that run in parallel threads crashed in my UAT environment. It seems the problem is in the AdjustToContents() method.
The full exception is:
---> System.InvalidOperationException: Object is currently in use elsewhere.
at System.Drawing.Graphics.MeasureString(String text, Font font, SizeF layoutArea, StringFormat stringFormat)
at System.Drawing.Graphics.MeasureString(String text, Font font, Int32 width, StringFormat format)
at ClosedXML.Excel.FontBaseExtensions.GetWidth(IXLFontBase fontBase, String text, Dictionary`2 fontCache)
at ClosedXML.Excel.XLColumn.AdjustToContents(Int32 startRow, Int32 endRow, Double minWidth, Double maxWidth)
at ClosedXML.Excel.XLColumns.<AdjustToContents>b__8(XLColumn c)
at System.Collections.Generic.List`1.ForEach(Action`1 action)
at ClosedXML.Excel.XLColumns.AdjustToContents()
Comments: For the sake of completeness, I did a short look through the source code of the 0.73 release and found the following issues wrt thread-safety, mostly the above repeats throughout the code. XLCFConverters: Dictionary, only read MathTrig.cs: Random XLCell.cs: Regex, Dictionary, only read XLColor.cs: Dictionaries, both r/w Extensions.cs: Regex, Dictionary (r/w), Graphics object PathHelper.cs: Regex XLHelper.cs: Regex, Dictionaries (r/w) ResourceFileExtractor.cs: Dictionary with cached objects, the lock is wrong here: lock (ms_defaultExtractors) (don't lock the object, use a lock object) I personally think that most of the thread issues are not as important as the graphics object issue. The impact should be smaller.
I have recently upgraded from 0.65 to 0.73 and while I have seen some performance improvements, several reports that run in parallel threads crashed in my UAT environment. It seems the problem is in the AdjustToContents() method.
The full exception is:
---> System.InvalidOperationException: Object is currently in use elsewhere.
at System.Drawing.Graphics.MeasureString(String text, Font font, SizeF layoutArea, StringFormat stringFormat)
at System.Drawing.Graphics.MeasureString(String text, Font font, Int32 width, StringFormat format)
at ClosedXML.Excel.FontBaseExtensions.GetWidth(IXLFontBase fontBase, String text, Dictionary`2 fontCache)
at ClosedXML.Excel.XLColumn.AdjustToContents(Int32 startRow, Int32 endRow, Double minWidth, Double maxWidth)
at ClosedXML.Excel.XLColumns.<AdjustToContents>b__8(XLColumn c)
at System.Collections.Generic.List`1.ForEach(Action`1 action)
at ClosedXML.Excel.XLColumns.AdjustToContents()
Comments: For the sake of completeness, I did a short look through the source code of the 0.73 release and found the following issues wrt thread-safety, mostly the above repeats throughout the code. XLCFConverters: Dictionary, only read MathTrig.cs: Random XLCell.cs: Regex, Dictionary, only read XLColor.cs: Dictionaries, both r/w Extensions.cs: Regex, Dictionary (r/w), Graphics object PathHelper.cs: Regex XLHelper.cs: Regex, Dictionaries (r/w) ResourceFileExtractor.cs: Dictionary with cached objects, the lock is wrong here: lock (ms_defaultExtractors) (don't lock the object, use a lock object) I personally think that most of the thread issues are not as important as the graphics object issue. The impact should be smaller.