【问题标题】:Set only maximum worker threads in ThreadPool.SetMaxThreads c#在 ThreadPool.SetMaxThreads c# 中仅设置最大工作线程
【发布时间】:2015-02-04 13:47:54
【问题描述】:
ThreadPool.SetMaxThreads(int workerThreads, int completionPortThreads)

SetMaxThreads 方法需要设置工作线程和完成端口线程。有什么方法可以让我只设置最大工作线程并让线程池决定完成端口线程。

如果没有解决方案,当workerThreads计数为6时,端口线程是否有推荐值。

我正在使用此代码将 SSIS 包从需要大约 10 到 20 秒才能执行的代码中排队。

系统信息: Intel Core i3-3220 Processor(双核,4线程)

【问题讨论】:

  • 你可以调用GetMaxThreads获取当前completionPortThreads的值,然后在SetMaxThreads方法中重新设置,所以值会和原来一样
  • 谢谢。那应该可以解决我的问题。 :)
  • SetMaxThreads() 往往被滥用来解决 tp 线程受 I/O 限制的问题。在修补 SSIS 时肯定有可能。在这种情况下,不更改完成线程的最大数量几乎没有意义。它实际上所做的只是让 DBA 很糟糕。
  • @HansPassant 我遇到过一些文章,要求我不要设置线程池最大线程,但不设置最大线程会降低我的电脑速度。希望这会起作用,否则需要创建一个自定义线程池来解决这个问题。不过谢谢你的提示。

标签: c# multithreading threadpool


【解决方案1】:

您可以使用 GetMaxThreads 获取当前线程,并且只更改 workerThreads..

//get value
ThreadPool.GetMaxThreads(out maxWorker, out maxCompletionThreads);

//set only workerThreads
ThreadPool.SetMaxThreads(differentValue, maxCompletionThreads);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-11-28
    • 1970-01-01
    • 2010-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-09
    相关资源
    最近更新 更多