This project has moved. For the latest updates, please go here.

Multithread not supported ?

Jan 10, 2012 at 11:56 AM

Hello,

First of all thank you very much for this library.
Very powerful & easy to use.
I am trying to generate reports in parallel to save some time but unfortunately when trying to use the library via 2 threads at the same time it locks my application. Any clue ? When I'll have some time I'll try to investigate with the source code.
Thank you to let me know if there is a special way to handle multithread.

 

TiramisuBxl

Sep 5, 2012 at 2:27 PM

I have the same problem, any one has an idea?

Thanks,

Editor
Sep 5, 2012 at 4:54 PM

I think it is not possible because System.IO.Packaging isn't thread safety. 

Coordinator
Sep 5, 2012 at 7:26 PM

Threading works until the package get to about 1MB of size (compressed). Then the package api starts to use Isolated storage. IS is for some strange reason not thread safe, and will hang even though you use different instances.

Sep 6, 2012 at 6:03 AM

Hi,

I solved the issue by modifying the EPPlus code, I added a critical section in the save function.

@Jan, wouldn't it be interesting to have a thread safe function save ? Leave the current one so people can use it in parallel for small files and save time but for big files save only 1 by 1. Or even better find a way to have an estimate of the file size so when we know it can hang we save with the critical section.

What do you think ?

Regards.

Nov 15, 2012 at 5:03 PM

Has anyone found a work around for this?  I have 100 reports to generate, all 3-10MiB in size and taking around 2-5 minutes to build.  Doing this in parallel would be so much quicker.  I haven't looked at the relevant code (it's almost pub o'clock for me, and this has just become an issue for me), but would locking the calls to IS with a mutex solve this issue?  

http://social.msdn.microsoft.com/Forums/en-US/wpdevelop/thread/b6779758-0d8d-4fb9-93d6-ea642c8a02db/

If no one has some code for this, I'll see if I get time tomorrow to give it a go.

Nov 16, 2012 at 10:07 AM
Edited Nov 16, 2012 at 10:35 AM

Add a private static object to ExcelPackage and wrap the innards of the Save() method with a lock on the object.

This appears to work with some basic spreadsheets. I noticed that charts reference IO.Packaging, and I haven't tried a spreadsheet with a chart.  I'm under time pressure to deliver this project so I can only justify testing areas that affect me.

System.IO.Packaging is referenced quite a few times throughout the project making it difficult to wrap the relevant areas in mutexes. I'm not familiar with this namespace as its not an area I have any use for in my usual work, but using proxy object that wraps the IO.Packaging classes would probably work if a more fine grained approach is necessary.

I'll do some more testing.

Coordinator
Nov 19, 2012 at 8:24 PM

I have replaced the Packaging API with DotNetZip in CoreChanges bransch. Feel free to test it if you are having problems with mulithreading...

http://epplus.codeplex.com/SourceControl/changeset/view/af16b68ec2e5

 

Nov 19, 2012 at 9:02 PM

When do you expect this change to be released?

Coordinator
Nov 21, 2012 at 6:13 AM

I'm not sure, but it will not be in the near future. I would guess in the middle of next year.

Sep 12, 2013 at 7:06 PM
Does release 3.1.3 support multithreaded use now?
Editor
Sep 12, 2013 at 7:20 PM
No, not yet. I don't have any info but there is no more dotnetzip branch, maybe Jan had some issues and aborted this change.
Oct 1, 2013 at 9:36 PM
It's still there, it's just rolled up in the branch called "FormulaParser." I've been using it without issues.

Has anyone approached Jan about taking over this project? The progress has been very slow, and I fear this entire library will be abandoned soon if we can't get some traction on moving some of these major updates into a new stable version.
Nov 11, 2013 at 11:49 PM
@richardtalent, are you saying if I use that branch I should be able to create different worksheets in parallel and call save without doing any locking on my end?
Developer
Nov 17, 2013 at 8:20 AM
zippy1981 - the FormulaParser branch has a totally rewritten cellstore, which does not utilize System.IO.Packaging, so it has hopefully less issues when it comes to threading. But keep in mind that this branch is currently under development, Jan is working on this right now and I dont think he has got all functionality covered yet.