Thread Safety in Utils.CalcColorBlend?

TeeChart for Microsoft Visual Studio .NET, Xamarin Studio (Android, iOS & Forms) & Monodevelop.
Post Reply
Scanrate
Newbie
Newbie
Posts: 5
Joined: Wed May 12, 2010 12:00 am
Location: Denmark
Contact:

Thread Safety in Utils.CalcColorBlend?

Post by Scanrate » Mon Aug 23, 2010 9:18 am

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.

Yeray
Site Admin
Site Admin
Posts: 9612
Joined: Tue Dec 05, 2006 12:00 am
Location: Girona, Catalonia
Contact:

Re: Thread Safety in Utils.CalcColorBlend?

Post by Yeray » Wed Aug 25, 2010 12:59 pm

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.
Best Regards,
ImageYeray Alonso
Development & Support
Steema Software
Av. Montilivi 33, 17003 Girona, Catalonia (SP)
Image Image Image Image Image Image Please read our Bug Fixing Policy

Post Reply