本文整理匯總了VB.NET中System.Threading.Tasks.TaskFactory<TResult>類的典型用法代碼示例。如果您正苦於以下問題:VB.NET TaskFactory<TResult>類的具體用法?VB.NET TaskFactory<TResult>怎麽用?VB.NET TaskFactory<TResult>使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了TaskFactory<TResult>類的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的VB.NET代碼示例。
示例1: Main
' 導入命名空間
Imports System.IO
Imports System.Threading.Tasks
Module Example
Public Sub Main()
Dim tasks(1) As Task(Of String())
Dim docsDirectory As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
tasks(0) = Task(Of String()).Factory.StartNew( Function()Directory.GetFiles(docsDirectory) )
'' End Sub )
tasks(1) = Task(Of String()).Factory.StartNew( Function() Directory.GetDirectories(docsDirectory) )
'' End Sub )
Task.Factory.ContinueWhenAll(tasks, Sub(completedTasks)
Console.WriteLine("{0} contains: ", docsDirectory)
Console.WriteLine(" {0} subdirectories", tasks(1).Result.Length)
Console.WriteLine(" {0} files", tasks(0).Result.Length)
End Sub)
End Sub
End Module
輸出:
C:\Users\\Documents contains: 24 subdirectories 16 files
示例2: Example
' 導入命名空間
Imports System.Collections.Generic
Imports System.Threading
Imports System.Threading.Tasks
Module Example
Public Sub Main()
Dim cts As New CancellationTokenSource()
Dim factory As New TaskFactory(Of Integer)(
cts.Token,
TaskCreationOptions.PreferFairness,
TaskContinuationOptions.ExecuteSynchronously,
New CustomScheduler())
Dim t2 = factory.StartNew(Function() DoWork())
cts.Dispose()
End Sub
Function DoWork() As Integer
Return If(Date.Now.Hour <= 12, 1, 2)
End Function
End Module