Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4241698
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T03:20:37+00:00 2026-05-21T03:20:37+00:00

My WPF program loads data from multiple CSV files into a Line Chart (each

  • 0

My WPF program loads data from multiple CSV files into a Line Chart (each file into its own LineSeries). This takes some time (rendering the GUI unusable) so I wanted to do this operation in a seperate thread and display a loading message (The BusyIndicator from the Extended WPF Toolkit).

Unfortunately when I try to create a LineSeries in the BackgroundWorker, I get an exception: “The calling thread must be STA, because many UI components require this.” I’m trying to copy the GUI’s chart, populate the copy, then it to the GUI’s chart upon completion. So this shouldn’t be trying to access a control from a different thread.

    /// <summary>
    /// Loads data from the collections into the chart
    /// </summary>
    private void populateChart()
    {
        // Begin working: Pass chart and data to the worker (wrapped in a class)
        this.chartWorker.RunWorkerAsync(new ChartWorkerArgs()
        {
            chart = chart,
            data = model.getAllCollections()
        });
    }

    /// <summary>
    /// Populates a provided Chart with provided data.
    /// </summary>
    private void chartWorker_DoWork(object sender, DoWorkEventArgs e)
    {
        // ...

        // Iterate through each one
        foreach (XYCollection collection in data)
        {
            // Create a new LineSeries and configure it
            LineSeries ls = new LineSeries();  // <-----------ERROR
            ls.ItemsSource = collection;
            ls.IndependentValueBinding = new Binding("X");
            ls.DependentValueBinding = new Binding("Y");
            ls.Title = collection.Name;
            chart.Series.Add(ls);
        }

        // Send the pouplated chart back
        e.Result = chart;
    }

    /// <summary>
    /// After chart has been populated (or cancelled), update chart.
    /// </summary>
    private void chartWorker_RunWorkerCompleted(
        object sender, RunWorkerCompletedEventArgs e)
    {
        // ... 
        // Set the GUI's chart as the newly populated chart
        this.chart = (Chart)e.Result;
        // ... 
    }

From what I’ve read elsewhere, its not possible to make a BackgroundWorker STA, so is there some other way I can load the chart with data without hanging the GUI?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T03:20:37+00:00Added an answer on May 21, 2026 at 3:20 am

    You could use a plain Thread. Then you have the control (ownership) to make it STA.

    The Bgw adds just a few handy features to interact with the GUI, nothing you can’t write yourself in a few lines of code. You’re not even using the UpdateProgress.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have installed WPF Toolkit: Location: C:\Program Files\WPF Toolkit\v3.5.40320.1\WPFToolkit.dll Name: WPFToolkit, Version=3.5.40128.1, Culture=neutral, PublicKeyToken=31bf3856ad364e35
I am trying to modify App.cs and load the WPF XAML files from code
How stable is WPF not in terms of stability of a WPF program, but
I have a problem with my WPF program. I'm trying to create an object
Have a look at this very simple example WPF program: <Window x:Class=WpfApplication1.Window1 xmlns=http://schemas.microsoft.com/winfx/2006/xaml/presentation xmlns:x=http://schemas.microsoft.com/winfx/2006/xaml
I'm writing a utility program with C# in WPF that allows users to create
I made a WPF/C# program and I am using the internet control for WYSIWYG
I have a program with two modes: GUI & Just Run. GUI loads a
Im running a console app that loads a dll and calls a method from
I'm currently working on a program in C# WPF. I use an external dll

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.