RadChart multithread safe

Thread is closed for posting
7 posts, 1 answers
  1. Tebba
    Tebba avatar
    5 posts
    Member since:
    Feb 2012

    Posted 21 Feb 2012 Link to this post

    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,
  2. Tebba
    Tebba avatar
    5 posts
    Member since:
    Feb 2012

    Posted 23 Feb 2012 Link to this post

    anyone ? 
  3. UI for ASP.NET Ajax is Ready for VS 2017
  4. Petar Marchev
    Admin
    Petar Marchev avatar
    968 posts

    Posted 24 Feb 2012 Link to this post

    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.
    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?


    Greetings,
    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.
  5. Tebba
    Tebba avatar
    5 posts
    Member since:
    Feb 2012

    Posted 24 Feb 2012 Link to this post

    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(150150150),
            Color.FromArgb(215215214),
            Color.FromArgb(230230230),
            Color.FromArgb(241241241),
            Color.FromArgb(224224224)
        }, new Color[]
        {
            Color.FromArgb(194194194),
            Color.FromArgb(241241241),
            Color.FromArgb(249249249),
            Color.FromArgb(248249248),
            Color.FromArgb(255255255)
        }));

    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.



  6. Tebba
    Tebba avatar
    5 posts
    Member since:
    Feb 2012

    Posted 24 Feb 2012 Link to this post

    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,
  7. Answer
    Giuseppe
    Admin
    Giuseppe avatar
    2363 posts

    Posted 29 Feb 2012 Link to this post

    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:
    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.
  8. Tebba
    Tebba avatar
    5 posts
    Member since:
    Feb 2012

    Posted 29 Feb 2012 Link to this post

    Hi,

    Problem solved.
     
    Thank you very much.

Back to Top
UI for ASP.NET Ajax is Ready for VS 2017