这不会导致无限递归,因为同名方法
Close ()
被召集到不同的班级。您引用的代码来自
WaitHandle
类。其中的私有字段具有不同的类型:
private SafeWaitHandle? _waitHandle;
如果你继续挖掘,
SafeHandle
(这是父母
SafeWaitHandle
)具有字段和抽象方法:
// https://github.com/dotnet/runtime/blob/1d1bf92fcf43aa6981804dc53c5174445069c9e4/src/libraries/System.Private.CoreLib/src/System/Runtime/InteropServices/SafeHandle.cs
protected IntPtr handle;
protected abstract bool ReleaseHandle();
ReleaseHandle()
在部分中被覆盖
.cs
文件并解析为WinAPI本机调用
CloseHandle (handle)
:
// https://github.com/microsoft/referencesource/blob/master/mscorlib/microsoft/win32/safehandles/safewaithandle.cs
override protected bool ReleaseHandle()
{
return Win32Native.CloseHandle(handle);
}
主要的收获是
System.Threading
类是WinAPI系统对象的精简包装。一切最终都必须解析为WinAPI调用。
另请参见:
Dispose
pattern by Microsoft
.