本文整理汇总了VB.NET中System.ComponentModel.AsyncOperationManager类的典型用法代码示例。如果您正苦于以下问题:VB.NET AsyncOperationManager类的具体用法?VB.NET AsyncOperationManager怎么用?VB.NET AsyncOperationManager使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了AsyncOperationManager类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: CalculatePrimeAsync
' This method starts an asynchronous calculation.
' First, it checks the supplied task ID for uniqueness.
' If taskId is unique, it creates a new WorkerEventHandler
' and calls its BeginInvoke method to start the calculation.
Public Overridable Sub CalculatePrimeAsync( _
ByVal numberToTest As Integer, _
ByVal taskId As Object)
' Create an AsyncOperation for taskId.
Dim asyncOp As AsyncOperation = _
AsyncOperationManager.CreateOperation(taskId)
' Multiple threads will access the task dictionary,
' so it must be locked to serialize access.
SyncLock userStateToLifetime.SyncRoot
If userStateToLifetime.Contains(taskId) Then
Throw New ArgumentException( _
"Task ID parameter must be unique", _
"taskId")
End If
userStateToLifetime(taskId) = asyncOp
End SyncLock
' Start the asynchronous operation.
Dim workerDelegate As New WorkerEventHandler( _
AddressOf CalculateWorker)
workerDelegate.BeginInvoke( _
numberToTest, _
asyncOp, _
Nothing, _
Nothing)
End Sub