C# Класс KiloWatt.Runtime.Support.ThreadPoolComponent

You typically only create a single ThreadPoolComponent in your application, and let all your threaded tasks run within this component. This allows for ideal thread balancing. If you have multiple components, they will not know how to share the CPU between them fairly.
Наследование: Microsoft.Xna.Framework.GameComponent
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
AddTask ( TaskFunction function, TaskComplete completion, TaskContext ctx ) : System.Threading.Task

Add a task to the thread queue. When a thread is available, it will dequeue this task and run it. Once complete, the task will be marked complete, but your application won't be called back until the next time Update() is called (so that callbacks are from the main thread).

DeliverComplete ( ) : void

Deliver all complete tasks. This is usually called for you, but can be called by you if you know that some tasks have completed.

NewTaskContext ( ) : TaskContext
ThreadPoolComponent ( Microsoft.Xna.Framework.Game game ) : System

Create the ThreadPoolComponent in your application constructor, and add it to your Components collection. The ThreadPool will deliver any completed tasks first in the update order. On Xbox, creates 3 threads. On PC, creates one or more threads, depending on the number of CPU cores. Always creates at least one thread. The thread tasks are assumed to be computationally expensive, so more threads than there are CPU cores is not recommended.

Update ( GameTime gameTime ) : void

Защищенные методы

Метод Описание
Dispose ( bool disposing ) : void

Disposing the ParallelThreadPool component will immediately deliver all work items with an object disposed exception.

Приватные методы

Метод Описание
NewWorker ( TaskFunction tf, TaskComplete tc ) : Worker
Reclaim ( TaskContext ctx ) : void
ThreadFunc ( ) : void
WorkOne ( ) : void

Описание методов

AddTask() публичный Метод

Add a task to the thread queue. When a thread is available, it will dequeue this task and run it. Once complete, the task will be marked complete, but your application won't be called back until the next time Update() is called (so that callbacks are from the main thread).
public AddTask ( TaskFunction function, TaskComplete completion, TaskContext ctx ) : System.Threading.Task
function TaskFunction The function to call within the thread.
completion TaskComplete The callback to report results to, or null. If /// you care about which particular task has completed, use a different instance /// for this delegate per task (typically, a delegate on the task itself).
ctx TaskContext A previously allocated TaskContext, to allow for waiting /// on the task, or null. It cannot have been already used.
Результат System.Threading.Task

DeliverComplete() публичный Метод

Deliver all complete tasks. This is usually called for you, but can be called by you if you know that some tasks have completed.
public DeliverComplete ( ) : void
Результат void

Dispose() защищенный Метод

Disposing the ParallelThreadPool component will immediately deliver all work items with an object disposed exception.
protected Dispose ( bool disposing ) : void
disposing bool
Результат void

NewTaskContext() публичный Метод

public NewTaskContext ( ) : TaskContext
Результат TaskContext

ThreadPoolComponent() публичный Метод

Create the ThreadPoolComponent in your application constructor, and add it to your Components collection. The ThreadPool will deliver any completed tasks first in the update order. On Xbox, creates 3 threads. On PC, creates one or more threads, depending on the number of CPU cores. Always creates at least one thread. The thread tasks are assumed to be computationally expensive, so more threads than there are CPU cores is not recommended.
public ThreadPoolComponent ( Microsoft.Xna.Framework.Game game ) : System
game Microsoft.Xna.Framework.Game Your game instance.
Результат System

Update() публичный Метод

public Update ( GameTime gameTime ) : void
gameTime Microsoft.Xna.Framework.GameTime
Результат void