Some corrections to the MSCoree Interface interops.

September 16, 2007

Recently I got a comment on my last post that it was throwing up exceptions. I realised the bad things in the code. Here is the revised version of the same

// CLSID_CorRuntimeHost from MSCOREE.DLL

[ Guid(“CB2F6723-AB3A-11D2-9C40-00C04FA30A3E”), ComImport]
class CorRuntimeHost {}

// IID_IcorThreadPool  

[ Guid(“84680D3A-B2C1-46e8-ACC2-DBC0A359159A”),InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
public interface ICorThreadpool {
// Note that IUnknown Interface members are NOT listed here:
void RegisterWaitForSingleObject();
void UnregisterWait(); 

void QueueUserWorkItem();
void CreateTimer(); 
void ChangeTimer(); 
void DeleteTimer(); 
void BindIoCompletionCallback(); 
void CallOrQueueUserWorkItem();
void SetMaxThreads(uint MaxWorkerThreads, uint MaxIOCompletionThreads);
void GetMaxThreads(out uint MaxWorkerThreads, out uint MaxIOCompletionThreads);
void GetAvailableThreads(out uint AvailableWorkerThreads, out uint AvailableIOCompletionThreads);}

//Here is the sample code for the consumption of these types. CorRuntimeHost runtimeMgr = new CorRuntimeHost();
// QueryInterface for the ICorThreadPool interface
ICorThreadpool coreThreadPool = (ICorThreadpool)runtimeMgr;
uint maxWorkerThreads;
uint maxIOThreads;
coreThreadPool.GetMaxThreads(
out maxWorkerThreads, out maxIOThreads); // this returned me 50, 1000
coreThreadPool.SetMaxThreads(25,1000); //setting max of 25 threads

//end code

This code is tested on .NET 2.0, and if you face any issues for 1.0 or 1.1 please let me know.-Bugs!

Advertisements

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: