小问题

橘子皮... 2018-01-02 01:16:40

Imports System.Threading
Imports System.Threading.Tasks

Module ContinuationDemo
' Demonstrated features:
' Task.Factory
' Task.ContinueWith()
' Task.Wait()
' Expected results:
' A sequence of three unrelated tasks is created and executed in this order - alpha, beta, gamma.
' A sequence of three related tasks is created - each task negates its argument and passes is to the next task: 5, -5, 5 is printed.
' A sequence of three unrelated tasks is created where tasks have different types.
' Documentation:
' http://msdn.microsoft.com/en-us/library/system.threading.tasks.taskfactory_members(VS.100).aspx
Sub Main()
Dim action As Action(Of String) = Sub(str) Console.WriteLine("Task={0}, str={1}, Thread={2}", Task.CurrentId, str, Thread.CurrentThread.ManagedThreadId)

' Creating a sequence of action tasks (that return no result).
Console.WriteLine("Creating a sequence of action tasks (that return no result)")
' Continuations ignore antecedent data
Task.Factory.StartNew(Sub() action("alpha")).ContinueWith(Sub(antecendent) action("beta")).ContinueWith(Sub(antecendent) action("gamma")).Wait()


Dim negate As Func(Of Integer, Integer) = Function(n)
Console.WriteLine("Task={0}, n={1}, -n={2}, Thread={3}", Task.CurrentId, n, -n, Thread.CurrentThread.ManagedThreadId)
Return -n
End Function

' Creating a sequence of function tasks where each continuation uses the result from its antecendent
Console.WriteLine(vbLf & "Creating a sequence of function tasks where each continuation uses the result from its antecendent")
Task(Of Integer).Factory.StartNew(Function() negate(5)).ContinueWith(Function(antecendent) negate(antecendent.Result)).ContinueWith(Function(antecendent) negate(antecendent.Result)).Wait()


' Creating a sequence of tasks where you can mix and match the types
Console.WriteLine(vbLf & "Creating a sequence of tasks where you can mix and match the types")
Task(Of Integer).Factory.StartNew(Function() negate(6)).ContinueWith(Sub(antecendent) action("x")).ContinueWith(Function(antecendent) negate(7)).Wait()
End Sub
End Module


1:
Dim negate As Func(Of Integer, Integer) 这句括号里前面那个integer是函数func的参数,后面那个是返回值类型??? 那就是除了最后1个是返回值类型,前面多少个都是参数类型是么

2:
Task(Of Integer).Factory.StartNew(Function() negate(5)).ContinueWith(Function(antecendent)。。。
这句里的antecendent 是表示前一个函数task的意思是么, task(of integer)里的integer是参数类型?


...全文
517 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
清晨曦月 元老 2018-01-05
  • 打赏
  • 举报
回复
1、那家伙是个委托。Func(Of In T,Out TResult)这么个东西,好像有那么十七八个重载的样子吧。你的理解应该就是对的了。 2、这个家伙是一个有返回值的异步操作,应该是这样的Task(Of TResult)来着,也就是说是返回值类型。 对于这个很长的这个东西吧,阅读起来确实挺烦的,一层一层的剥惯了就好了,ContinueWith(Sub(antecendent) action("x"))是一伙的。
  • 打赏
  • 举报
回复
这样的问题其实不需要问,查看有关VB的文档即可了解其定义. https://docs.microsoft.com/zh-cn/dotnet/visual-basic/

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧