在vb.net如何使用parallel来提高处理任务的速度,麻烦举个例子谢谢 50
1个回答
展开全部
例子1:
Dim result As ParallelLoopResult = Parallel.[For](0, 10, Function(i)
Console.WriteLine("{0}, task: {1} , thread: {2}", i, Task.CurrentId, Thread.CurrentThread.ManagedThreadId)
Thread.Sleep(10)
End Function)
Console.WriteLine(result.IsCompleted)
例子2:
Parallel.For(Of String)(0, 20,
Function()
Console.WriteLine("init thread {0}, task {1}", Thread.CurrentThread.ManagedThreadId, Task.CurrentId)
Return String.Format("t: {0}", Thread.CurrentThread.ManagedThreadId)
End Function,
Function(i, pls, str)
Console.WriteLine("body i {0} str1 {1} thread {2} task {3}", i, str, Thread.CurrentThread.ManagedThreadId, Task.CurrentId)
Return String.Format("i {0}", i)
End Function,
Function(str1)
Console.WriteLine("finally {0}", str1)
End Function)
追问
麻烦能在样子一中给个具体的例子吗??谢谢
来自:求助得到的回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询