1 | #Region "Microsoft.VisualBasic::7ba103898e4e26cf2720c0cae8dabff3, Microsoft.VisualBasic.Core\ApplicationServices\Parallel\Threading.vb" |
2 | |
3 | ' Author: |
4 | ' |
5 | ' asuka (amethyst.asuka@gcmodeller.org) |
6 | ' xie (genetics@smrucc.org) |
7 | ' xieguigang (xie.guigang@live.com) |
8 | ' |
9 | ' Copyright (c) 2018 GPL3 Licensed |
10 | ' |
11 | ' |
12 | ' GNU GENERAL PUBLIC LICENSE (GPL3) |
13 | ' |
14 | ' |
15 | ' This program is free software: you can redistribute it and/or modify |
16 | ' it under the terms of the GNU General Public License as published by |
17 | ' the Free Software Foundation, either version 3 of the License, or |
18 | ' (at your option) any later version. |
19 | ' |
20 | ' This program is distributed in the hope that it will be useful, |
21 | ' but WITHOUT ANY WARRANTY; without even the implied warranty of |
22 | ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
23 | ' GNU General Public License for more details. |
24 | ' |
25 | ' You should have received a copy of the GNU General Public License |
26 | ' along with this program. If not, see <http://www.gnu.org/licenses/>. |
27 | |
28 | |
29 | |
30 | ' /********************************************************************************/ |
31 | |
32 | ' Summaries: |
33 | |
34 | ' Module InvokesHelper |
35 | ' |
36 | ' Function: Invoke |
37 | ' Structure __invokeHelper |
38 | ' |
39 | ' Function: Task |
40 | ' |
41 | ' |
42 | ' |
43 | ' |
44 | ' /********************************************************************************/ |
45 | |
46 | #End Region |
47 | |
48 | Imports System.Runtime.CompilerServices |
49 | Imports Microsoft.VisualBasic.Language |
50 | Imports Microsoft.VisualBasic.Parallel.Threads |
51 | |
52 | Namespace Parallel |
53 | |
54 | Public Module InvokesHelper |
55 | |
56 | ''' <summary> |
57 | ''' |
58 | ''' </summary> |
59 | ''' <param name="tasks"></param> |
60 | ''' <param name="numOfThreads">同时执行的句柄的数目</param> |
61 | ''' <returns></returns> |
62 | ''' <remarks></remarks> |
63 | <Extension> Public Function Invoke(tasks As Action(), numOfThreads As Integer) As Integer |
64 | Dim getTask As Func(Of Action, Func(Of Integer)) = |
65 | Function(task) AddressOf New __invokeHelper With { |
66 | .__task = task |
67 | }.Task |
68 | Dim invokes As Func(Of Integer)() = |
69 | LinqAPI.Exec(Of Func(Of Integer)) <= From action As Action |
70 | In tasks |
71 | Select getTask(action) |
72 | Return BatchTasks.BatchTask(invokes, numOfThreads).Length |
73 | End Function |
74 | |
75 | Private Structure __invokeHelper |
76 | |
77 | Dim __task As Action |
78 | |
79 | Public Function Task() As Integer |
80 | Call __task() |
81 | Return 0 |
82 | End Function |
83 | End Structure |
84 | End Module |
85 | End Namespace |