本文整理汇总了VB.NET中System.Threading.Tasks.TaskFactory类的典型用法代码示例。如果您正苦于以下问题:VB.NET TaskFactory类的具体用法?VB.NET TaskFactory怎么用?VB.NET TaskFactory使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了TaskFactory类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Main
' 导入命名空间
Imports System.IO
Imports System.Threading.Tasks
Module Example
Public Sub Main()
Dim tasks(1) As Task
Dim files() As String = Nothing
Dim dirs() As String = Nothing
Dim docsDirectory As String = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments)
tasks(0) = Task.Factory.StartNew( Sub()
files = Directory.GetFiles(docsDirectory)
End Sub )
tasks(1) = Task.Factory.StartNew( Sub()
dirs = Directory.GetDirectories(docsDirectory)
End Sub )
Task.Factory.ContinueWhenAll(tasks, Sub(completedTasks)
Console.WriteLine("{0} contains: ", docsDirectory)
Console.WriteLine(" {0} subdirectories", dirs.Length)
Console.WriteLine(" {0} files", files.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(cts.Token,
TaskCreationOptions.PreferFairness,
TaskContinuationOptions.ExecuteSynchronously,
New CustomScheduler())
Dim t2 = factory.StartNew(Sub() DoWork())
cts.Dispose()
End Sub
Sub DoWork()
' ...
End Sub
End Module