Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
Application Background: Desktop app designed in WPF and vb.net backed-up by sql server express edition 2008 for multiple users across the workgroup.
 
We are trying to refresh the data periodically into the datagrids using dispatchertimers. The problem is that even after setting the datacontexts of the datagrids from a delegate function call through a dispatcher the UI still freezes and we are not able to update the progressbars. I would like to know if this approach is totally wrong? or we are missing something when it comes to wiring the threads/processes?
 
example: (In code behind)
Private WithEvents timer1 As DispatcherTimer
Dim WithEvents dOP As DispatcherOperation
Delegate Sub updatemainUIDelegate()
 
Private Sub timer1_tick(ByVal sender As Object, ByVal e As EventArgs) Handles timer1.Tick
'...       
dOP = Me.RefreshDataBtn.Dispatcher.BeginInvoke(DispatcherPriority.Background, (New updatemainUIDelegate(AddressOf updateMainUI)))
'...
End Sub
 
Public Sub updateMainUI()
       
            Debug.Print("Updating UI")
            Me.RecentWorkOrdersDataGrid.DataContext = PMS_DistributableDataSetRecentWorkOrdersTableAdapter.Fill(PMSDS.RecentWorkOrders)
            Me.RecentProposalsDataGrid.DataContext = PMS_DistributableDataSetRecentProposalsTableAdapter.Fill(PMSDS.RecentProposals)
'(several datagrids and tableadapters to refresh)
'...
End Sub
(In XAML)
<Window x:Class="MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml /presentation" xmlns:my1="clr-namespace:PMS_WPF">
<Window.Resources>
        <myPMS:PMS_DistributableDataSet x:Key="PMS_DistributableDataSet" />
        <CollectionViewSource x:Key="WorkOrdersViewSource" Source="{Binding Path=WorkOrders, Source={StaticResource PMS_DistributableDataSet}}" />
        <CollectionViewSource x:Key="ProjectsViewSource" Source="{Binding Path=Projects, Source={StaticResource PMS_DistributableDataSet}}" />
        <!--... -->
      <DataGrid ItemsSource="{Binding Source={StaticResource RecentWorkOrdersViewSource}}" Name="RecentWorkOrdersDataGrid" ... />
 
What can be done to prevent the UI freeze and refresh of the datagrids asynchronously?
 
(Note:
1. The data can be refreshed manually/at chosen time interval by user i.e. 15/30/45 mins.
2. Please do not explain on disadvantages of such refreshing i.e. simultaneous edits/updates etc...it has been taken care of.
3. We are using the tables and tableadapters and mapping created in the .xsd automatically. Could not find enough solutions anywhere with this combination hence the question)
 
Thanks in advance!
Posted 26-Mar-11 21:33pm
WPFNub280
Edited 26-Mar-11 21:55pm
v6

1 solution

Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Since I could not get any answers from this forum, I posted it on MSDN and I have posted the final approach here: http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/cf3fbd6f-1d8a-47b5-b87b-5c7d8bd1c963
  Permalink  
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 OriginalGriff 480
1 Maciej Los 290
2 Richard MacCutchan 225
3 BillWoodruff 185
4 Suraj Sahoo | Coding Passion 155
0 OriginalGriff 8,764
1 Sergey Alexandrovich Kryukov 7,437
2 DamithSL 5,639
3 Maciej Los 5,279
4 Manas Bhardwaj 4,986


Advertise | Privacy | Mobile
Web04 | 2.8.1411028.1 | Last Updated 27 Jun 2011
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100