Fail to update chart in UI thread

A forum dedicated to WPF version of LightningChart Ultimate.

Moderator: Queue Moderators

Post Reply
hallo888
Posts: 43
Joined: Wed Mar 26, 2014 10:56 am

Fail to update chart in UI thread

Post by hallo888 » Fri Jul 25, 2014 9:30 am

Hi

I am using a WorkerThread to load data from a text file. Once the loading completes, a handler in the xxx.xaml.cs file will be invoked. In the handler, i used lightningchart.Dispatcher.CheckAccess() to check whether the current thread owns the control. Seems like it is not, thus i used the dispatcher instead.

lightningchart.Dispatcher.Invoke((Action)(() =>
{
drawChart();
}));

void drawChart()
{
lightningchart.BeginUpdate();

// my codes to update the chart.

lightningchart.EndUpdate();
}

Inside the drawChart() function, i tried to set the title of the chart, set the x-axis range, etc., but it doesn't get updated into the chart. Any idea why? If I do not have the WorkerThread, there is no issue.

Thanks!

ArctionJari

Re: Fail to update chart in UI thread

Post by ArctionJari » Fri Jul 25, 2014 10:31 am

Does it work if you replace "lightningchart" with "this" (in both CheckAccess and Invoke).

In general you don't need to use CheckAccess since Invoke uses it internally. I.e. if synchronization is not needed Invoke will call the target method/delegate directly, otherwise it will synchronize the call to the owning UI thread. If you are not sure if thread synchronization is needed, use Invoke method every time.

hallo888
Posts: 43
Joined: Wed Mar 26, 2014 10:56 am

Re: Fail to update chart in UI thread

Post by hallo888 » Mon Jul 28, 2014 2:27 pm

Hi

lightningchart is the name of the chart. Using the chartname in the constructor pose no issue. However, after creating the WorkerThread, updating the chart via a function in the class using invoke has the issue.

I have checked that the attributes to the chart are set correctly. Is there a way to check why the chart is not updated at all?

Thanks.

hallo888
Posts: 43
Joined: Wed Mar 26, 2014 10:56 am

Re: Fail to update chart in UI thread

Post by hallo888 » Tue Jul 29, 2014 11:39 am

Hi

I also replaced "lightningchart" with "this" (in both CheckAccess and Invoke), but it still doesn't work.

ArctionJari

Re: Fail to update chart in UI thread

Post by ArctionJari » Wed Jul 30, 2014 10:37 am

Sounds weird... Can you send you project to us so we can debug it? For example to our support email or let us know where to download it if you have an FTP server etc. to upload the project.

hallo888
Posts: 43
Joined: Wed Mar 26, 2014 10:56 am

Re: Fail to update chart in UI thread

Post by hallo888 » Thu Jul 31, 2014 10:01 am

Hi

My bad. I actually created 2 charts, with one hidden. I was updating the hidden chart, hence it was not shown on the displayed one.

Now, i've solved the issue.

Post Reply