Page 1 of 1

Thread Safety in Utils.CalcColorBlend?

Posted: Mon Aug 23, 2010 9:18 am
by 15656148
Hi,

I've been having some threading issues that seem to be related to TeeChart. I'm getting the following exception when my code is executed (by ASP.NET IIS) in several simultaneous requests:

Code: Select all

System.InvalidOperationException: Object is currently in use elsewhere. 
at System.Drawing.Graphics.FromImage(Image image) 
at Steema.TeeChart.Utils.CalcColorBlend(Color start, Color end, Int32 percentage) 
at Steema.TeeChart.Styles.Series.ModifySeriesColors(Color color) 
at Steema.TeeChart.Styles.CustomBar.ModifySeriesColors(Color color) 
at Steema.TeeChart.Styles.Series.Added() 
at Steema.TeeChart.Styles.SeriesCollection.Add(Series s) 
at Steema.TeeChart.Styles.Series..ctor(Chart c) 
at Steema.TeeChart.Styles.CustomBar..ctor(Chart c) 
at Steema.TeeChart.Styles.Bar..ctor(Chart c) 
My own code indicates, as expected from the stacktrace, that this happens when I call new Bar(ch); (ch being my Chart-object).

Using Reflector, it seems to stem from the fact that the Utils-class maintains a static Bitmap instance for calculating default gradient colors using FillRect and GetPixel. So when two Bars are constructed simultaneously, they both attempt to retrieve Graphics-handles for the same Bitmap. This seems odd and unnecessary. I would expect the calculation to be a simple linear progression which can be handled by multiplication, which should be much more efficient as well.

Is there some way I can avoid the (unnecessary) calculation, as I'm using solid colors for my bars? Or are there plans to fix this bug?

My TeeChart.dll is listed as v. 4.0.2010.13051.

Re: Thread Safety in Utils.CalcColorBlend?

Posted: Wed Aug 25, 2010 12:59 pm
by yeray
Hi Scanrate,

TeeChart is not thread-safe so you should control the accesses from different threads with semaphores or other threading techniques.

However, if you could arrange a simple example we could run as-is to reproduce the problem here, we will try to propose a workaround this issue and we'll investigate if we can skip the calculations you mention safety or not.