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)
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!