下面这个程序有一个bug,试试看你能不能抓住它。

Test.cs (编译成 DelegateExample.exe):

    usingSystem;usingSystem.Threading;usingSystem.Runtime.InteropServices;classTest
{
delegate uintThreadProc (IntPtr arg);private uintm;public Test (uintn)
{
m
=n;
}
uintReflect (IntPtr arg)
{
Console.WriteLine (m);
returnm;
}
static voidMain ()
{
Test t
= new Test (1);
ThreadProc tp
= newThreadProc (t.Reflect);
NewThread (tp);
Thread.Sleep (
1000);
}

[DllImport(
"UsingCallback")]static extern voidNewThread (ThreadProc proc);
}

标签: none

添加新评论