Stride

OPEN / CLOSE
  • Features
  • Blog
  • Documentation
  • Community
(icon) Download

  • Discord
  • Facebook
  • Twitter
  • YouTube

LANGUAGE

OPEN / CLOSE
  • English
  • 日本語
    Show / Hide Table of Contents

    ThreadPool Class

    Namespace: Stride.Core.Threading
    Assembly: Stride.Core.dll

    Thread pool for scheduling sub-millisecond actions, do not schedule long-running tasks. Can be instantiated and generates less garbage than dotnet's.

    System.Object → ThreadPool
    Derived from ThreadPool:

    public sealed class ThreadPool : IDisposable
    Name Description
    Constructors
    ThreadPool(Nullable<Int32>)
    Fields
    Instance

    The default instance that the whole process shares, use this one to avoid wasting process memory.

    WorkerThreadsCount

    Amount of threads within this pool

    Properties
    CompletedWork

    Amount of work completed

    IsWorkedThread

    Is the thread reading this property a worker thread

    ThreadsBusy

    Amount of threads currently executing work items

    WorkScheduled

    Amount of work waiting to be taken care of

    Methods
    Dispose()
    QueueWorkItem(Action, Int32)

    Queue an action to run on one of the available threads, it is strongly recommended that the action takes less than a millisecond.

    TryCooperate()

    Attempt to steal work from the threadpool to execute it from the calling thread. If you absolutely have to block inside one of the threadpool's thread for whatever reason do a busy loop over this function.

    | Improve this Doc View Source

    Constructors


    ThreadPool(Nullable<Int32>)

    public ThreadPool(int? threadCount = null)
    Parameters
    Type Name Description
    System.Nullable<System.Int32> threadCount
    | Improve this Doc View Source

    Fields


    Instance

    The default instance that the whole process shares, use this one to avoid wasting process memory.

    public static ThreadPool Instance
    Field Value
    Type Description
    ThreadPool

    WorkerThreadsCount

    Amount of threads within this pool

    public readonly int WorkerThreadsCount
    Field Value
    Type Description
    System.Int32
    | Improve this Doc View Source

    Properties


    CompletedWork

    Amount of work completed

    public ulong CompletedWork { get; }
    Property Value
    Type Description
    System.UInt64

    IsWorkedThread

    Is the thread reading this property a worker thread

    public static bool IsWorkedThread { get; }
    Property Value
    Type Description
    System.Boolean

    ThreadsBusy

    Amount of threads currently executing work items

    public int ThreadsBusy { get; }
    Property Value
    Type Description
    System.Int32

    WorkScheduled

    Amount of work waiting to be taken care of

    public int WorkScheduled { get; }
    Property Value
    Type Description
    System.Int32
    | Improve this Doc View Source

    Methods


    Dispose()

    public void Dispose()

    QueueWorkItem(Action, Int32)

    Queue an action to run on one of the available threads, it is strongly recommended that the action takes less than a millisecond.

    public void QueueWorkItem(Action workItem, int amount = 1)
    Parameters
    Type Name Description
    System.Action workItem
    System.Int32 amount

    TryCooperate()

    Attempt to steal work from the threadpool to execute it from the calling thread. If you absolutely have to block inside one of the threadpool's thread for whatever reason do a busy loop over this function.

    public bool TryCooperate()
    Returns
    Type Description
    System.Boolean

    Extension Methods

    ComponentBaseExtensions.DisposeBy<T>(T, ICollectorHolder)
    ComponentBaseExtensions.RemoveDisposeBy<T>(T, ICollectorHolder)
    • Improve this Doc
    • View Source
    In This Article

    Back to top

    Copyright © 2019-2021 .NET Foundation and Contributors
    Supported by the .NET Foundation