Hi!
> I'm trying to create a hook using 2.0 following the below example, but
> the AppDomain.GetCurrentThreadID is now obsolete.
Because managed Threads must not be implemented as OS - Threads. You cannot
assume that a managed Thread has always an unmanaged counterpart.
> I have tried
> replacing it with Thread.CurrentThread.ManagedThreadID, but it returns
> 0, so it is failing.
It is not failing. The Thread.ManagedThreadID property is just an Identifier
which is unique within your process. The MangededThreadID is no handle or a
OS-ThreadID.
> What do I need to do to get this to work??
Because the current CLR implements managed Threads with OS-Threads, you can
still use the AppDomain.GetCurrentThreadID Method. But if you program runs
on a CLR that do not use OS Threads to implement managed Threads (what about
the SQL 2005 CLR? I can configure the SQL-Server to use fibers instead of
Threads. Maybe the SQL CLR uses Fibers also for managed Threads? It would be
possible to check this), you application will fail.
Another possiblity would be to use the unmanaged GetCurrentThreadId
function:
http://msdn.microsoft.com/library/en-us/dllproc/base/getcurrentthreadid.asp
[DllImport("kernel32.dll")]
static extern int GetCurrentThreadId();
OK?
GP