【发布时间】:2013-09-10 22:37:30
【问题描述】:
我目前正在研究处理来自 WCF 服务的 2 个数据下载,这些服务返回不同对象的集合,并且想知道是否有比同步运行这两个异步任务更好的方法。
在这种情况下,我可以实现Task.WhenAll 或Task.WhenAny 方法来并行运行这些任务吗?
Public Property Users As IEnumerable(Of UserDto)
Get
Return _users
End Get
Set(value As IEnumerable(Of UserDto))
_users = value
RaisePropertyChanged("Users")
End Set
End Property
Public Property ApplicationRoles() As IEnumerable(Of ApplicationRoleDto)
Get
Return _roles
End Get
Set(ByVal value As IEnumerable(Of ApplicationRoleDto))
_roles = value
RaisePropertyChanged("ApplicationRoles")
End Set
End Property
Private Async Sub GetUserDetails()
Users = Await _serviceHelper.GetUsers()
ApplicationRoles = Await _serviceHelper.GetApplicationRoles
End Sub
可能的解决方案
我可以使用Task Parrallel Library,但我不确定这是否是最有效的方法,而且我不能等待返回。
Parallel.Invoke(Sub() Users = _serviceHelper.GetUsers(),
Sub() ApplicationRoles = _serviceHelper.GetApplicationRoles())
【问题讨论】:
标签: vb.net task-parallel-library .net-4.5 async-await