CSDN博客

img beyond_ml

设置CLR线程池的默认大小

发表于2004/6/26 23:53:00  1095人阅读

在Codeproject看到了一片好文章介绍如何重新设置.NET的CLR线程池大小。

首先明确负责设置线程池默认大小的COM对象的GUID是:

 // Declare ThreadManager as a COM coclass:
 [
  // CLSID_CorRuntimeHost from MSCOREE.DLL
  Guid("CB2F6723-AB3A-11D2-9C40-00C04FA30A3E"),ComImport
 ]
 class ThreadManager   // Cannot have a base class or
  // interface list here.
 {
  // Cannot have any members here
  // NOTE that the C# compiler will add a default constructor
  // for you (no parameters).
 }

其次声明组件的Interface是:

 [
 // IID_IcorThreadPool
 Guid("84680D3A-B2C1-46e8-ACC2-DBC0A359159A"),
 InterfaceType(ComInterfaceType.InterfaceIsIUnknown)
 ]
 public interface ICorThreadpool   // Cannot list any base interfaces here
 {
  // Note that IUnknown Interface members are NOT listed here:

  void RegisterWaitForSingleObject(); // Not Implemeted.
  void UnregisterWait(); //  Not Implemeted.
  void QueueUserWorkItem(); //  Not Implemeted.
  void CreateTimer(); //  Not Implemeted.
  void ChangeTimer(); //  Not Implemeted.
  void DeleteTimer(); //  Not Implemeted.
  void BindIoCompletionCallback(); //  Not Implemeted.
  void CallOrQueueUserWorkItem();  // Not Implemeted.
  void SetMaxThreads( uint MaxWorkerThreads, uint MaxIOCompletionThreads );
  void GetMaxThreads(  out uint MaxWorkerThreads, out uint MaxIOCompletionThreads );
  void GetAvailableThreads( out uint AvailableWorkerThreads, out uint AvailableIOCompletionThreads );
 }

Ok,然后就可以这样设置了:

ThreadManager threadManager = new ThreadManager();

// QueryInterface for the ICorThreadPool interface:
MSCoreeTypeLib.ICorThreadpool  ct = (MSCoreeTypeLib.ICorThreadpool)threadManager;

int maxWorkerThreads = 35;
int maxIOThreads = 35;
ct.SetMaxThreads(maxWorkerThreads, maxIOThreads);

 

阅读全文
0 0

相关文章推荐

img
取 消
img