Force a specific processor affinity on an unmanaged DLL call from VB.NET

260 views Asked by At

I am calling a function from a VB.NET webserver to a custom written unmanaged DLL. If we call this DLL via a webservice on a multi-core server we run into problems and it always crashes.

If I reboot the server and make it only use a single-core, it always runs fine and never crashes.

I know the DLL call is responsible for the crash as I have outputted debugging code just before and after the DLL call.

I can force the processor affinity of the .NET code to 1 core but this doesn't apply to the unmanaged DLL.

How can I force the unmanaged DLL to only run on a single core as I am sure this will solve the problem?

1

There are 1 answers

1
boto On

If you have access to the DLL code then you can use something like the following lines in DllMain:

DWORD_PTR processAffinityMask = 0x1;

SetProcessAffinityMask( GetCurrentProcess(), processAffinityMask );

This will set the process affinity of the dll to the first CPU.