Hello,
How can i make RadChart multi-thread safe ?
I get the following error "Non unique name for palette in collection." when i try to run it in multi-thread environment the following statemenet "RadChart chart = new RadChart();"
Thanks,
How can i make RadChart multi-thread safe ?
I get the following error "Non unique name for palette in collection." when i try to run it in multi-thread environment the following statemenet "RadChart chart = new RadChart();"
Thanks,
6 Answers, 1 is accepted
0

Tebba
Top achievements
Rank 1
answered on 23 Feb 2012, 02:40 PM
anyone ?
0
Hello Tebba,
Could you elaborate a bit more on how did you run the chart in multi-thread environment as our local tests were unable to reproduce the described exception. Below I have pasted the code I have used in a new project and it does not throw any exception.
Have you tried running your code in the main thread?
Greetings,
Petar Marchev
the Telerik team
Could you elaborate a bit more on how did you run the chart in multi-thread environment as our local tests were unable to reproduce the described exception. Below I have pasted the code I have used in a new project and it does not throw any exception.
protected
void
Page_Load(
object
sender, EventArgs e)
{
Thread t =
new
Thread(
new
ThreadStart(() =>
{
Thread.Sleep(3000);
RadChart rc =
new
RadChart();
}));
t.Start();
}
Have you tried running your code in the main thread?
Petar Marchev
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0

Tebba
Top achievements
Rank 1
answered on 24 Feb 2012, 02:52 PM
Hello,
Thanks for responding. What it think it happens is:
In the RadChart constructor is the following line
this.chart = new Chart(this);
So this creates an instance of Chart. The Chart class has a property named paletteCollection which is:
internal ChartSeriesPaletteCollection paletteCollection = new ChartSeriesPaletteCollection(); This property is going to be initialized when the constructor of Chart is called. This init is going to be executed for every instance of Chart and RadChart created.
The ChartSeriesPaletteCollection class has a property named List which is static. The constructor of ChartSeriesPaletteCollection initialize the list
ChartSeriesPaletteCollection.List = new ArrayList();
and then fills up the list:
this.Add(new ChartSeriesPalette("Default", new Color[]
{
Color.FromArgb(150, 150, 150),
Color.FromArgb(215, 215, 214),
Color.FromArgb(230, 230, 230),
Color.FromArgb(241, 241, 241),
Color.FromArgb(224, 224, 224)
}, new Color[]
{
Color.FromArgb(194, 194, 194),
Color.FromArgb(241, 241, 241),
Color.FromArgb(249, 249, 249),
Color.FromArgb(248, 249, 248),
Color.FromArgb(255, 255, 255)
}));
The add method check if the palette exists and if exists throws an error.
if (this.Get(value.Name) != null)
{
throw new Exception("Non unique name for palette in collection.");
}
So the List property, which is static, is going to be renewed for every new created instance of chart.
Now if 2 threads come in the same time, and both threads execute the statement List = new ArrayList(); and then the add statement, one of them is going to fail :).
I think now is pretty obvious where the problem is, but please tell me if you need more details.
PS: The List property should be in a static constructor. Doing this, it will only be initialized once and is guaranteed to be thread safe.
Thanks for responding. What it think it happens is:
In the RadChart constructor is the following line
this.chart = new Chart(this);
So this creates an instance of Chart. The Chart class has a property named paletteCollection which is:
internal ChartSeriesPaletteCollection paletteCollection = new ChartSeriesPaletteCollection(); This property is going to be initialized when the constructor of Chart is called. This init is going to be executed for every instance of Chart and RadChart created.
The ChartSeriesPaletteCollection class has a property named List which is static. The constructor of ChartSeriesPaletteCollection initialize the list
ChartSeriesPaletteCollection.List = new ArrayList();
and then fills up the list:
this.Add(new ChartSeriesPalette("Default", new Color[]
{
Color.FromArgb(150, 150, 150),
Color.FromArgb(215, 215, 214),
Color.FromArgb(230, 230, 230),
Color.FromArgb(241, 241, 241),
Color.FromArgb(224, 224, 224)
}, new Color[]
{
Color.FromArgb(194, 194, 194),
Color.FromArgb(241, 241, 241),
Color.FromArgb(249, 249, 249),
Color.FromArgb(248, 249, 248),
Color.FromArgb(255, 255, 255)
}));
The add method check if the palette exists and if exists throws an error.
if (this.Get(value.Name) != null)
{
throw new Exception("Non unique name for palette in collection.");
}
So the List property, which is static, is going to be renewed for every new created instance of chart.
Now if 2 threads come in the same time, and both threads execute the statement List = new ArrayList(); and then the add statement, one of them is going to fail :).
I think now is pretty obvious where the problem is, but please tell me if you need more details.
PS: The List property should be in a static constructor. Doing this, it will only be initialized once and is guaranteed to be thread safe.
0

Tebba
Top achievements
Rank 1
answered on 24 Feb 2012, 02:55 PM
What you did in the page load is not going to reproduce my problem, because you are not creating multiple threads, you are creating a thread that creates a RadChart.
Thank you,
Thank you,
0
Accepted
Hello Tebba,
It seems you are referring to the now obsolete RadChart for ASP.NET and not to the RadChart for ASP.NET AJAX control indicated in this ticket as the latter does not have either ChartSeriesPalette, or ChartSeriesPaletteCollection classes. As a matter of fact the whole RadControls for ASP.NET suite has been discontinued for some time now in favor of the RadControls for ASP.NET AJAX suite and we neither distribute RadControls for ASP.NET, nor do we support it or fix any issues with it any more.
We would suggest you to upgrade to RadControls for ASP.NET AJAX (and RadChart for ASP.NET AJAX) that seems to behave as expected in a scenario where multiple threads are created like this:
Greetings,
Giuseppe
the Telerik team
It seems you are referring to the now obsolete RadChart for ASP.NET and not to the RadChart for ASP.NET AJAX control indicated in this ticket as the latter does not have either ChartSeriesPalette, or ChartSeriesPaletteCollection classes. As a matter of fact the whole RadControls for ASP.NET suite has been discontinued for some time now in favor of the RadControls for ASP.NET AJAX suite and we neither distribute RadControls for ASP.NET, nor do we support it or fix any issues with it any more.
We would suggest you to upgrade to RadControls for ASP.NET AJAX (and RadChart for ASP.NET AJAX) that seems to behave as expected in a scenario where multiple threads are created like this:
protected
void
Page_Load(
object
sender, EventArgs e)
{
Thread t =
new
Thread(
new
ThreadStart(() =>
{
while
(
true
)
{
RadChart rc =
new
RadChart();
}
}));
Thread t2 =
new
Thread(
new
ThreadStart(() =>
{
while
(
true
)
{
RadChart rc =
new
RadChart();
}
}));
Thread t3 =
new
Thread(
new
ThreadStart(() =>
{
while
(
true
)
{
RadChart rc =
new
RadChart();
}
}));
t.Start();
t2.Start();
t3.Start();
}
Greetings,
Giuseppe
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0

Tebba
Top achievements
Rank 1
answered on 29 Feb 2012, 03:06 PM
Hi,
Problem solved.
Thank you very much.
Problem solved.
Thank you very much.