1 | #Region "Microsoft.VisualBasic::05bb33847252690ed3d803df761b8650, Microsoft.VisualBasic.Core\ApplicationServices\Parallel\Threads\ParallelExtension.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 ParallelExtension |
35 | ' |
36 | ' Function: AsyncTask, RunTask |
37 | ' |
38 | ' |
39 | ' /********************************************************************************/ |
40 | |
41 | #End Region |
42 | |
43 | Imports System.Runtime.CompilerServices |
44 | Imports System.Threading |
45 | Imports Microsoft.VisualBasic.MethodsExtension |
46 | |
47 | Namespace Parallel |
48 | |
49 | ''' <summary> |
50 | ''' Parallel based on the threading |
51 | ''' </summary> |
52 | Public Module ParallelExtension |
53 | |
54 | ''' <summary> |
55 | ''' Start a new thread and then returns the background thread task handle. |
56 | ''' </summary> |
57 | ''' <param name="start"></param> |
58 | ''' <returns></returns> |
59 | <Extension> Public Function RunTask(start As ThreadStart) As Thread |
60 | Dim thread As New Thread(start) |
61 | Call thread.Start() |
62 | Return thread |
63 | End Function |
64 | |
65 | ' 2018-10-6 |
66 | ' 下面的这个函数会导致函数调用的时候重载失败 |
67 | '<MethodImpl(MethodImplOptions.AggressiveInlining)> |
68 | '<Extension> Public Function RunTask(method As Action) As Thread |
69 | ' Return New ThreadStart(AddressOf method.Method.Invoke).RunTask |
70 | 'End Function |
71 | |
72 | ''' <summary> |
73 | ''' 运行一个后台任务 |
74 | ''' </summary> |
75 | ''' <param name="start"></param> |
76 | ''' <returns></returns> |
77 | Public Function AsyncTask(start As ThreadStart) As IAsyncResult |
78 | Return start.BeginInvoke(Nothing, Nothing) |
79 | End Function |
80 | End Module |
81 | End Namespace |