K
Kevin Frey
Using .NET 1.1.
We have a mixed-mode assembly written in Managed C++ that we are using from
an ASP.NET application that has been coded using C#. The mixed-mode assembly
has its own "initialisation" routine to cater for any potential "mixed-mode
DLL loading problem".
Some of our code uses thread-local-storage, and in the DllMain for my
mixed-mode assembly I did the appropriate initialisation of the
thread-local-storage object on THREAD_ATTACH, cleaning it up on
THREAD_DETACH.
When the assembly is used from ASP.NET, I don't see the THREAD_ATTACH or
DETACH.
Now I understand from reading Microsoft's documentation that
THREAD_ATTACH/DETACH are not posted to DllMain for pre-existing threads.
Looking at aspnet_wp.exe, on my machine (WXP Pro), it starts with 14 threads
and when I start a couple of web requests the number of threads increases to
17. Fairly soon my assembly fails because it is attempting to use the
thread-local-storage but the slot has not been initialised.
My workaround for the moment is to perform allocation of the
thread-local-storage object when it is requested, if it is not already
present, but I don't like this approach because if I don't see the
THREAD_ATTACH/DETACH I'll never know when to clean it up.
The most confusing thing is understanding how aspnet_wp.exe can create a new
thread but those threads don't produce corresponding THREAD_ATTACH'es in my
assembly.
Does anyone have any experience with this who might be able to offer an
explanation?
Thanks
Kevin
We have a mixed-mode assembly written in Managed C++ that we are using from
an ASP.NET application that has been coded using C#. The mixed-mode assembly
has its own "initialisation" routine to cater for any potential "mixed-mode
DLL loading problem".
Some of our code uses thread-local-storage, and in the DllMain for my
mixed-mode assembly I did the appropriate initialisation of the
thread-local-storage object on THREAD_ATTACH, cleaning it up on
THREAD_DETACH.
When the assembly is used from ASP.NET, I don't see the THREAD_ATTACH or
DETACH.
Now I understand from reading Microsoft's documentation that
THREAD_ATTACH/DETACH are not posted to DllMain for pre-existing threads.
Looking at aspnet_wp.exe, on my machine (WXP Pro), it starts with 14 threads
and when I start a couple of web requests the number of threads increases to
17. Fairly soon my assembly fails because it is attempting to use the
thread-local-storage but the slot has not been initialised.
My workaround for the moment is to perform allocation of the
thread-local-storage object when it is requested, if it is not already
present, but I don't like this approach because if I don't see the
THREAD_ATTACH/DETACH I'll never know when to clean it up.
The most confusing thing is understanding how aspnet_wp.exe can create a new
thread but those threads don't produce corresponding THREAD_ATTACH'es in my
assembly.
Does anyone have any experience with this who might be able to offer an
explanation?
Thanks
Kevin