本文整理汇总了VB.NET中System.Threading.Tasks.Parallel.Invoke方法的典型用法代码示例。如果您正苦于以下问题:VB.NET Parallel.Invoke方法的具体用法?VB.NET Parallel.Invoke怎么用?VB.NET Parallel.Invoke使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Threading.Tasks.Parallel
的用法示例。
在下文中一共展示了Parallel.Invoke方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: InvokeDemo
' 导入命名空间
Imports System.Threading
Imports System.Threading.Tasks
Module InvokeDemo
' Demonstrated features:
' Parallel.Invoke()
' Expected results:
' The threads on which each task gets executed may be different.
' The thread assignments may be different in different executions.
' The tasks may get executed in any order.
' Documentation:
' http://msdn.microsoft.com/library/dd783942(VS.100).aspx
Private Sub Main()
Try
' Param #0 - static method
Parallel.Invoke(AddressOf BasicAction,
Sub()
' Param #1 - lambda expression
Console.WriteLine("Method=beta, Thread={0}", Thread.CurrentThread.ManagedThreadId)
End Sub,
Sub()
' Param #2 - in-line delegate
Console.WriteLine("Method=gamma, Thread={0}", Thread.CurrentThread.ManagedThreadId)
End Sub)
Catch e As AggregateException
' No exception is expected in this example, but if one is still thrown from a task,
' it will be wrapped in AggregateException and propagated to the main thread.
Console.WriteLine("An action has thrown an exception. THIS WAS UNEXPECTED." & vbLf & "{0}", e.InnerException.ToString())
End Try
End Sub
Private Sub BasicAction()
Console.WriteLine("Method=alpha, Thread={0}", Thread.CurrentThread.ManagedThreadId)
End Sub
End Module