本文整理汇总了VB.NET中System.Threading.Tasks.Task<TResult>.Factory属性的典型用法代码示例。如果您正苦于以下问题:VB.NET Task<TResult>.Factory属性的具体用法?VB.NET Task<TResult>.Factory怎么用?VB.NET Task<TResult>.Factory使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Threading.Tasks.Task<TResult>
的用法示例。
在下文中一共展示了Task<TResult>.Factory属性的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Module1
' 导入命名空间
Imports System.Threading.Tasks
Module Module1
Sub Main()
ReturnAValue()
Console.WriteLine("Press any key to exit.")
Console.ReadKey()
End Sub
Sub ReturnAValue()
' Return a value type with a lambda expression
Dim task1 = Task(Of Integer).Factory.StartNew(Function() 1)
Dim i As Integer = task1.Result
' Return a named reference type with a multi-line statement lambda.
Dim task2 As Task(Of Test) = Task.Factory.StartNew(Function()
Dim s As String = ".NET"
Dim d As Integer = 4
Return New Test With {.Name = s, .Number = d}
End Function)
Dim myTest As Test = task2.Result
Console.WriteLine(myTest.Name & ": " & myTest.Number)
' Return an array produced by a PLINQ query.
Dim task3 As Task(Of String())= Task(Of String()).Factory.StartNew(Function()
Dim path = "C:\Users\Public\Pictures\Sample Pictures\"
Dim files = System.IO.Directory.GetFiles(path)
Dim result = (From file In files.AsParallel()
Let info = New System.IO.FileInfo(file)
Where info.Extension = ".jpg"
Select file).ToArray()
Return result
End Function)
For Each name As String In task3.Result
Console.WriteLine(name)
Next
End Sub
Class Test
Public Name As String
Public Number As Double
End Class
End Module