C#获取程序在操作系统的线程
直接贴代码
```csharp
using System.Runtime.InteropServices;
public class Program
{
[DllImport("kernel32.dll")]
static extern uint GetCurrentThreadId();
public static void Main(string[] args)
{
uint threadId = GetCurrentThreadId();
System.Console.WriteLine("The thread ID is " + threadId);
}
}
这段代码定义了一个静态extern方法GetCurrentThreadId(), 这个方法在运行时会链接到Kernel32.dll的同名函数。Main()方法中调用了这个函数,并将结果打印到控制台。
+