Hello
I was wondering if there is a method that my class (or my assembly) can get
notified when a thread is created, in the same manner like DLL_THREAD_ATTA CH
event in DllMain in Win32 unmanaged dlls?
The reason I want to do this, is that I have thread static fields that I
want to be initialized when the new thread starts.
Here is my current work around for this problem
[ThreadStatic]
private static MyClass myField;
public static MyClass MyProperty
{
get
{
if(myField == null)
{
// Initialize my object
}
return myField;
}
}
This works fine, but is not efficient. I access myField through MyProperty
to make sure the MyField is properly initialized. From the code you see that
every time the property get is called the if statement is executed to check
that myField has been initialized. I want to eliminated this check and
execute it only once instead of executing everytime.
Best regards
Sherif
I was wondering if there is a method that my class (or my assembly) can get
notified when a thread is created, in the same manner like DLL_THREAD_ATTA CH
event in DllMain in Win32 unmanaged dlls?
The reason I want to do this, is that I have thread static fields that I
want to be initialized when the new thread starts.
Here is my current work around for this problem
[ThreadStatic]
private static MyClass myField;
public static MyClass MyProperty
{
get
{
if(myField == null)
{
// Initialize my object
}
return myField;
}
}
This works fine, but is not efficient. I access myField through MyProperty
to make sure the MyField is properly initialized. From the code you see that
every time the property get is called the if statement is executed to check
that myField has been initialized. I want to eliminated this check and
execute it only once instead of executing everytime.
Best regards
Sherif