Wednesday, February 19, 2003


using System;
using System.Threading;
using System.Runtime.InteropServices;

namespace ThreadStuff
{
class Class1
{
[DllImport("kernel32.dll", CharSet=CharSet.Auto)]
public extern static int GetCurrentThreadId();

[STAThread]
static void Main(string[] args)
{
Console.WriteLine("Begin Main(clr): " + System.AppDomain.GetCurrentThreadId().ToString() );
Console.WriteLine("Begin Main(win32): " + Class1.GetCurrentThreadId().ToString() );
Console.WriteLine("Begin Main(hash): " + Thread.CurrentThread.GetHashCode().ToString() );
Foo foo = new Foo();
ThreadStart threadStart = new ThreadStart( foo.Bar );
Thread thread = new Thread(threadStart);
thread.Start();
Console.WriteLine("End Main(clr): " + System.AppDomain.GetCurrentThreadId().ToString() );
Console.WriteLine("End Main(win32): " + Class1.GetCurrentThreadId().ToString() );
Console.WriteLine("End Main(hash): " + Thread.CurrentThread.GetHashCode().ToString() );
Console.ReadLine();
}
}

public class Foo
{
public void Bar()
{
Console.WriteLine("Bar(clr):" + System.AppDomain.GetCurrentThreadId().ToString() );
Console.WriteLine("Bar(win32): " + Class1.GetCurrentThreadId().ToString() );
Console.WriteLine("Bar(hash): " + Thread.CurrentThread.GetHashCode().ToString() );
}
}
}