Click here to Skip to main content
15,880,725 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
Application Background: Desktop app designed in WPF and 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

<Window x:Class="MainWindow" xmlns=" /presentation" xmlns:my1="clr-namespace:PMS_WPF">
        <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?

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 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!
Updated 26-Mar-11 20:55pm

1 solution

Since I could not get any answers from this forum, I posted it on MSDN and I have posted the final approach here:
Share this answer

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

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900