I can't seem to get an async fetch method to run asnyc within a caliburn micro confguration. The dp fetches the data properly, but it locks up the UI while it does so.
Are there any known issues with async dp used within CM and/or MEF? I don't think it's my data or business layers, but more likely something between csla and caliburn.
Again, the code below works, excpet that it locks up the UI.
EmployeeInfoList is readonly. Here is the method and dp:
#Region "Async Factory Methods" Public Shared Sub BeginFetch(ByVal callback As EventHandler(Of DataPortalResult(Of EmployeeInfoList))) DataPortal.BeginFetch(Of EmployeeInfoList)(callback) End Sub #End Region #Region " Data Access " Private Overloads Sub DataPortal_Fetch() Using dalManager = HCM.Dal.DalFactory.GetManager Dim dal = dalManager.GetProvider(Of Dal.IEmployeeDal)() Dim data = dal.FetchList IsReadOnly = False Dim rlce = RaiseListChangedEvents RaiseListChangedEvents = False For Each item As Dal.Dto.EmployeeDto In data Add(DataPortal.FetchChild(Of EmployeeInfo)(item)) Next RaiseListChangedEvents = rlce IsReadOnly = True End Using End Sub #End Region
My dal fetch function:
Public Function FetchList() As System.Collections.Generic.List(Of Dto.EmployeeDto) Implements IEmployeeDal.FetchList Dim result As New List(Of Dto.EmployeeDto) Using dal As New DalManager Using cn = dal.dbConnection Using cm = cn.Connection.CreateCommand cm.CommandType = CommandType.Text cm.CommandText = "Select * From EMPLOYEE" Using dr = New SafeDataReader(cm.ExecuteReader) While dr.Read result.Add(GetDto(dr)) End While End Using End Using End Using End Using For x = 1 To 9999 Console.WriteLine(x) Next ' Threading.Thread.Sleep(10000) Return result End Function
My view model:
Imports System.ComponentModel.Composition Imports Caliburn.Micro Imports HCM.Framework Imports CslaContrib.Caliburn.Micro <Export("List", GetType(IEmployeeScreen))> Public Class EmployeeListViewModel Inherits ScreenWithModel(Of Library.EmployeeInfoList) Implements IEmployeeScreen Protected Overrides Sub OnActivate() ManageObjectLifetime = True MyBase.OnActivate() If Me.Model Is Nothing Then Me.IsBusy = True BeginRefresh("BeginFetch") End If End Sub End Class
Which version of CSLA do you use?
We have used Caliburn Micro and CSLA 4.3.x with great success - but I haven't done any work yet on Csla 4.5.x and CM.
Initially, csla 4.5 via nuget. I then tried 4.3, but with the same results.
Ok, scratch that. The issue seems to be with csla 4.5. Async methods work properly with csla 4.3.13.
My initial problem with 4.3 was that I ignored the multiple binding conflict warning because things compiled, but just failed to async my dataportal fetch. But once I addressed the conflicts, the asnync fetches worked. To resolve the conflict I had to compile the cslacontrib.caliburn.micro.wpf source to use the same csla references.
CslaContrib.Caliburn.Micro is in the process of updating to Csla 4.5. A couple of days ago I published here a pre-release of full version of Caliburn.Micro with the Csla module matching the code on Csla 4.3.13 and the latest source of Caliburn.Micro.
Updating it to Csla 4.5 is the next step.
As CslaContrib is not updated to support async/await I would expect the code to work fine with Csla 4.5 for NET 4, as this version still has the "old" DataPortal implementation without async/await.
Did you try to reference Csla 4.5 for NET 4 in your app?
When I referenced csla 4.5 and net 4, the UI locked up during the dp fetch. When I changed my references to 4.3, the UI worked as expected.
Please try the following actions:
1) Use Visual Studio 2010
2) Set the target to Framework .NET 4.0
3) Remove all Csla references
4) Use NuGet to reference Csla 4.5.10
The NuGet packages are supposed to install all dependencies according to the target framework. This means the AsyncTargetingPack will show up on your project references if youir target is Framework .NET 4.0
I know this works all right for other kind of Csla projects.
Of course you must use a CslaContrib version retargeted to Csla 4.5.10. Use the port from https://docs.google.com/folder/d/0B0hxPXhUZfjIT1NxcnA2YmNoY1U/edit (this uses the commited CslaContrib code)
Please report back the result of these actions.
Tiago, thanks for your efforts, but that did not resolve the issue. Since the same configuration works with Csla 4.3, I am left with the feeling that something about 4.5 has changed which causes the UI to lock up.
The internal implementation of the old-style callback model async data portal methods did change between 4.3 and 4.5. The new implementation delegates to the new async/await implementations.
This is not problematic in any of the 'mainstream' scenarios, because the regression tests and sample apps (and some production apps that have been upgraded) work unchanged from 4.3 to 4.5.
My guess is that there's something going on with your code, and/or with MEF, that acts differently when running within a Task (now) as opposed to running in the previous callback model.
Thanks for the feedback and confirmation, Rocky, that something changed. The view and view model are imported into the shell via MEF from a separate assembly and I'm wondering if that has some compatibility issues with the new implementations.
When I have some time I'll try and put them in the same assembly and see if that makes a difference.
Upgrading to 4.5.2 fixes the problem.
Copyright (c) Marimer LLC