Thread safety

Jun 13, 2012 at 2:05 PM

Thank you for an excellent component!

I have a problem in a production environment where the epplus component just hangs.
The problem occurs when performing SaveXml in a multithreaded application on the ExcelWorksheet object.

Epplus works fine almost always but when my multithreaded app starts two excel exports simultaneously they always hang.

I've entered trace info the epplus sourcecode to try to pinpoint the problem:


It hangs inside UpdateRowCellData... The sw object is created with:

StreamWriter sw = new StreamWriter(Part.GetStream(FileMode.Create, FileAccess.Write));

I can see that one file is created in the isolatedstorage which i assume is handled by
(I'm not familiar with the package concept... )

When reading the the link above i found:

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe. 

This means that the GetStream method used to aquire the sw is not guaranteed to be thread safe. 

Does my text above make any sence?
How can I solve or further debug this?

Stefan Sundström


Jun 13, 2012 at 8:00 PM

hmm, yes, the package api doesn't seem to be thread safe, for some strange reason (and you can't only use the static methods). I haven't deep dived into this subject, but my guess is that this is related to isolated storage, so you will probably only notice this on quite large spreadsheet. I have no good idea how to solve this, but I will have a look at it when I get some time over, and get back to you. If you find something out, please let me know.



Jun 13, 2012 at 8:23 PM

I've done a little research too and for now I think the only way is change System.IO.Packaging to another one, like donetzip, but it isnt a simple task, there are a high coupling between epplus and packaging api. I tried two months ago because my hosting provider have trouble with isolated storage.