本文整理汇总了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