本文整理汇总了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
开发者ID:VB.NET开发者,项目名称:System.Threading.Tasks,代码行数:52,代码来源:Task.Factory
注:本文中的System.Threading.Tasks.Task<TResult>.Factory属性示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论