小问题

橘子皮... 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是参数类型?


...全文
512 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/
微信小程序系统教程[初级阶段],微信小程序0基础学起,讲解微信小程序开发的基础知识。 微信小程序系统教程共有“微信小程序系统教程[初级阶段]”、“微信小程序系统教程[中级阶段]——核心技术”、“微信小程序系统教程[阶段]客服消息+微信支付+九宝电商系统”。 “微信小程序系统教程[阶段]全套课程”包含: 1.微信小程序系统教程[阶段]_客服消息 2.微信小程序系统教程[阶段]_微信支付 3.微信小程序系统教程[阶段]_九宝电商系统 学习“微信小程序系统教程[阶段]”要求有微信小程序的基础。建议先学习“微信小程序系统教程[初级阶段]”、“微信小程序系统教程[中级阶段]”,后在报名“微信小程序系统教程[阶段]”。 阶段讲解的客服消息,是针对小程序的。后台程序用接近底层的技术,没有使用三方技术。这样降低同学们学习成本。 微信支付,这部分课程很有难度,要求同学们认真听讲,有不会的技术问题可以请教老师。购买课程后请联系老师,提供单号,给你源程序。 九宝电商系统是一套十分适和学习、项目的课程。既可以系统的学习微信小程序相关知识,还可以修改后上线。 “微信小程序系统教程[中级阶段]——核心技术”重点讲解微信小程序事件、组件、API 微信小程序系统教程[初级阶段],微信小程序0基础学起,讲解微信小程序开发的基础知识。 购买课程的同学,可赠送就九宝老师编写的《微信小程序开发宝典》。 购课请咨询qq2326321088

16,553

社区成员

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

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