views:

71

answers:

1

Good day.

I have started messing around with the MVVP pattern, and I am having some problems with UI responsiveness versus data processing.

I have a program that tracks packages. Shipment and package entities are persisted in SQL database, and are displayed in a WPF view. Upon initial retrieval of the records, there is a noticeable pause before displaying the new shipments view, and I have not even implemented the code that counts shipments that are overdue/active yet (which will necessitate a tracking check via web service, and a lot of time).

I have built this with the Ocean framework, and all appears to be doing well, except when I first started my foray into multi-threading. It broke, and it appeared to break something in Ocean... Here is what I did:

Private QueryThread As New System.Threading.Thread(AddressOf GetShipments)


Public Sub New()
    ' Insert code required on object creation below this point.

    Me.New(ViewManagerService.CreateInstance, ViewModelUIService.CreateInstance)
    'Perform initial query of shipments
    'QueryThread.Start()
    GetShipments()
    Console.WriteLine(Me.Shipments.Count)
End Sub



Public Sub New(ByVal objIViewManagerService As IViewManagerService, ByVal objIViewModelUIService As IViewModelUIService)
    MyBase.New(objIViewModelUIService)
End Sub



Public Sub GetShipments()
    Dim InitialResults = From shipment In db.Shipment.Include("Packages") _
                         Select shipment
    Me.Shipments = New ShipmentsCollection(InitialResults, db)
End Sub

So I declared a new Thread, assigned it the GetShipments method and instanced it in the default constructor. Ocean freaks out at this, so there must be a better way of doing it.

I have not had the chance to figure out the usage of the SQL ORM thing in Ocean so I am using Entity Framework (perhaps one of these days i will look at NHibernate or something too).

Any information would be greatly appreciated. I have looked at a number of articles and they all have examples of simple uses. Some have mentioned the Dispatcher, but none really go very far into how it is used. Anyone know any good tutorials?

Cory

+1  A: 

The way I do it is, using a backgroundworker. Then I use MVVM Light to send a message to the main ui to update progress.

Rick Ratayczak
That is what I have started doing. I was leaving this question open in case someone had something better. You get the answer and a +1.
OffApps Cory
Just remember to use the DispatcherHelper.UIDispatcher.Invoke to invoke methods on the UI. I've already got this baked up, if you want a sample, email rickrat at gmail com.
Rick Ratayczak