sklose / NCalc2

expression evaluator for .NET with built-in compiler
MIT License
166 stars 58 forks source link

Caching doesn't work in a multi threaded context #22

Closed fdahlberg closed 4 years ago

fdahlberg commented 5 years ago

Hi,

I noticed that NCalc often hangs when multiple threads are using it. I only use an ncalc expression object that is local to the method so I thought it should be thread safe. My application often freezes on the line: expression.HasErrors() When i looked in the debug window the error was: "Recursive read lock acquisitions not allowed in this mode"

I realized that this could have something to do with the caching in NCalc, so I turned it off by doing: Expression.CacheEnabled = false;

When I turn caching off everything works fine.

I realize this might be a tough one to get the bottom of, but I thought it was worth mentioning it.

Let me know if you want any more info.

Kind Regards Fredrik Dahlberg

XristophD commented 5 years ago

Hi, we experience the same issue with multi-threading and Cache enabled. Disabling the cache worked for us, too. Need to do some performance testing if it has a high impact on our overall solution.

Great work anyway, the library helps a lot in our case. Cheers Christoph