使用多条线程来执行任务队列,推荐在编写Web服务器的时候使用这个模块来执行任务
ThreadPool
01 Syntax
Microsoft.VisualBasic.Parallel.Threads.ThreadPool
02 Methods
| Name | Overloads | Summary |
|---|---|---|
| Start | 1 | Start the background task, and stop until the ThreadPool.Dispose() method has been called |
| GetStatus | 1 | 获取当前的这个线程池对象的状态的摘要信息 |
| RunTask | 2 | Push a new task into the parallel task queue. |
| OperationTimeOut | 1 | Run a speicifc task with assert of operation is time out or not. |
| allocate | 1 | allocate the task into the task thread pool |
| GetAvaliableThread | 1 | 这个函数总是会返回一个线程对象的 + 当有空闲的线程,会返回第一个空闲的线程 + 当没有空闲的线程,则会返回任务队列最短的线程 |
| WaitAll | 1 | |
| ToString | 1 | |
| Exit | 1 | |
| Dispose | 1 |
03 Properties
| Name | Overloads | Summary |
|---|---|---|
| NumOfThreads | 1 | 线程池之中的线程数量 |
| WorkingThreads | 1 | 返回当前正在处于工作状态的线程数量 |
| FullCapacity | 1 | 是否所有的线程都是处于工作状态的 |
04 Fields
| Name | Overloads | Summary |
|---|---|---|
| pendings | 1 | 临时的句柄缓存 |
05 Members
Start
Start the background task, and stop until the ThreadPool.Dispose() method has been called
GetStatus
获取当前的这个线程池对象的状态的摘要信息
RunTask(
Action(Of TaskWorker), Action(Of Int64), String)Push a new task into the parallel task queue. (使用线程池里面的空闲线程来执行任务)
Parameters
| Name | Type | Description |
|---|---|---|
task | Action(Of TaskWorker) | - |
callback | Action(Of Int64) | 回调函数里面的参数是任务的执行的时间长度 |
name | String | the name of current task |
RunTask(
Action, Action(Of Int64), String)Push a new task into the parallel task queue. (使用线程池里面的空闲线程来执行任务)
Parameters
| Name | Type | Description |
|---|---|---|
task | Action | - |
callback | Action(Of Int64) | 回调函数里面的参数是任务的执行的时间长度 |
name | String | the name of current task |
OperationTimeOut(
Action, Int32)Run a speicifc task with assert of operation is time out or not.
Parameters
| Name | Type | Description |
|---|---|---|
task | Action | A specific task to run |
timeout | Int32 | wait timeout in unit milliseconds |
Returns
- true means timeout, the task has not been finished;
- false means the task has been execute success without timeout
allocate
allocate the task into the task thread pool
GetAvaliableThread
这个函数总是会返回一个线程对象的
- 当有空闲的线程,会返回第一个空闲的线程
- 当没有空闲的线程,则会返回任务队列最短的线程
NumOfThreads
线程池之中的线程数量
WorkingThreads
返回当前正在处于工作状态的线程数量
FullCapacity
是否所有的线程都是处于工作状态的
pendings
临时的句柄缓存
WaitAll(
Boolean)ToString()
Exit()
Dispose()