SfCart code behind - interface that was marshalled for a different thread

Hi,
In my application we got 2 UWP pages (MainPage, SecondaryPage) and the corresponding diagrams (column and pie diagram) should be automatically generated through some code behind. So I created another class where this diagram code behind is managed.
When I want to open the SecondaryPage through the MainPage (the MainPage got a button to open the SecondaryPage) I got the following error message:
The application called an interface that was marshalled for a different thread. (Exception from HRESULT: 0x8001010E (RPC_E_WRONG_THREAD))
My code behind is the following method in the other class:
public SfChart createColumnDiagram()
{
SfChart columnDia = new SfChart();

columnDia.Header = "Demands Comparison";

//Adding horizontal axis to the chart
CategoryAxis primaryCategoryAxis = new CategoryAxis();
primaryCategoryAxis.Header = "Demands";
columnDia.PrimaryAxis = primaryCategoryAxis;

//Adding vertical axis to the chart
NumericalAxis secondaryNumericalAxis = new NumericalAxis();
secondaryNumericalAxis.Header = "Values";
columnDia.SecondaryAxis = secondaryNumericalAxis;

//Initialize the two series for SfChart
ColumnSeries series1 = new ColumnSeries();
series1.ItemsSource = this.Demands;
series1.XBindingPath = "Demand";
series1.YBindingPath = "Year2010";

ColumnSeries series2 = new ColumnSeries();
series2.XBindingPath = "Demand";
series2.YBindingPath = "Year2011";
series2.ItemsSource = this.Demands;

//Adding Series to the Chart Series Collection
columnDia.Series.Add(series1);
columnDia.Series.Add(series2);

//Adding Legends for the chart
ChartLegend legend = new ChartLegend();
columnDia.Legend = legend;

//return the created diagram
return columnDia;
}
The error occurs when the Method wants to set the CategoryAxis. 

Does anybody know a solution to this problem?

3 Replies

DS Durgadevi Selvaraj Syncfusion Team October 24, 2017 12:41 PM UTC


Hi Marvin, 
 
Thanks for contacting Syncfusion Support. 
 
We have analyzed and tried to reproduce the reported problem but unable to reproduced on our end. However, we have prepared a simple sample based on the provided information and please find the sample from the below link, 
 
Could you please revert us with more information about the problem or modifying the provide sample to reproduce the issue? So that, it would be more helpful for us to provide a solution as sooner. 
 
Regards,  
Durgadevi S 
  
  



MH Marvin Hartmann October 25, 2017 06:36 PM UTC

Thank you for the fast respond. Unfortunately we got the same exception. Based on your example I created a new Chart and Model class and created two Chart objects, one at the MainPage and one at the SecondaryPage. But in your example you simply switch between these two pages. We want to open a whole new window (based on SecondaryPage) through the following code:

private async void Button_Click(object sender, RoutedEventArgs e)

{ CoreApplicationView newView = CoreApplication.CreateNewView(); int newViewId = 0; await newView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => { Frame frame = new Frame(); frame.Navigate(typeof(SecondaryPage), null); Window.Current.Content = frame; // You have to activate the window in order to show it later. Window.Current.Activate(); newViewId = ApplicationView.GetForCurrentView().Id; }); bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(newViewId); }

So we got a button at the MainPage which executes the code above. The two constructors of the MainPage and SecondaryPage look like the following:

public SecondaryPage()    (or MainPage)
{
     this.InitializeComponent();
     Frame1.Content = chart1.createColumnDiagram();
}

The exception occurs when the Method createColumnDiagram() wants to set the CategoryAxis. It seems like the different properties of a SfChart are exclusively reserved for just one Window but we don't know why it should not be possible to create a diagram in two or more windows. 
Maybe we are taking the wrong approach to solve this kind of problem. 

Thank you for your help!



DS Durgadevi Selvaraj Syncfusion Team October 27, 2017 11:01 AM UTC

Hi Marvin, 
Thanks for the update. 
We have analyzed the reported problem and can able to reproduced the issue  on our end. The support incident to track the status of this problem has been created under your account. Please log on to our support website to check for further updates. 
 
Regards, 
Durgadevi S 


Loader.
Up arrow icon