zoukankan      html  css  js  c++  java
  • C#ThreadPool类—多线程

    标题:ThreadPool Class

    地址:https://docs.microsoft.com/zh-cn/dotnet/api/system.threading.threadpool?redirectedfrom=MSDN&view=netframework-4.8

    百度关键字看到了:ManualResetEvent

    Provides a pool of threads that can be used to execute tasks, post work items, process asynchronous I/O, wait on behalf of other threads, and process timers.

    提供一个线程池,可用于执行任务、发布工作项、处理异步I/O、代表其他线程等待和执行定时器。

    线程池运行以下情况:

    When you create a Task or Task<TResult> object to perform some task asynchronously, by default the task is scheduled to run on a thread pool thread.

    您创建一个任务或任务<TResult>对象来异步执行某些任务时,默认情况下,该任务将在线程池线程上运行。

    Asynchronous timers use the thread pool. Thread pool threads execute callbacks from the System.Threading.Timer class and raise events from the System.Timers.Timer class.

    异步计时器使用线程池。线程池线程从System.Threading.Timer类执行回调,并从System.Timers.Timer类引发事件。

    When you use registered wait handles, a system thread monitors the status of the wait handles. When a wait operation completes, a worker thread from the thread pool executes the corresponding callback function.

    使用已注册的等待句柄时,系统线程将监视等待句柄的状态。当等待操作完成时,线程池中的工作线程执行相应的回调函数。

    When you call the QueueUserWorkItem method to queue a method for execution on a thread pool thread. You do this by passing the method a WaitCallback delegate. The delegate has the signature

    当您调用QueueUserWorkItem方法对线程池线程上的执行方法进行排队时。您可以通过传递方法WaitCallback委托来实现这一点。委托具有签名。

    void WaitCallback(Object state)

    其中状态是一个对象,它包含要由委托使用的数据。可以通过调用QueueUserWorkItem(WaitCallback,Object)方法将实际数据传递给委托。

    注意:

    The threads in the managed thread pool are background threads. That is, their IsBackground properties are true. This means that a ThreadPool thread will not keep an application running after all foreground threads have exited.

    托管线程池中的线程是后台线程。也就是说,他们的IsBackplace属性是真实的。这意味着在所有前台线程退出之后,线程将不会继续运行应用程序。

  • 相关阅读:
    面向对象的JavaScript-009-闭包
    面向对象的JavaScript-007-Function.prototype.bind() 的4种作用
    面向对象的JavaScript-006-Function.prototype.apply()的3种作用
    面向对象的JavaScript-005-Function.prototype.call()的3种作用
    面向对象的JavaScript-004
    面向对象的JavaScript-003
    面向对象的JavaScript-002
    面向对象的JavaScript-001
    IOC容器特性注入第一篇:程序集反射查找
    AWS EC2 在WINDOWS平台使用FSX
  • 原文地址:https://www.cnblogs.com/Tpf386/p/11542500.html
Copyright © 2011-2022 走看看