我正在阅读一些 .NET 代码,我在 DispatcherSynchronizationContext
中发现了以下内容///
/// Wait for a set of handles.
///
///
/// Critical - Calls WaitForMultipleObjectsEx which has a SUC.
///
[SecurityCritical]
[SecurityPermissionAttribute(SecurityAction.LinkDemand, Flags=SecurityPermissionFlag.ControlPolicy|SecurityPermissionFlag.ControlEvidence)]
public override int Wait(IntPtr[] waitHandles, bool waitAll, int millisecondsTimeout)
{
if(_dispatcher._disableProcessingCount > 0)
{
// Call into native code directly in order to avoid the default
// CLR locking behavior which pumps messages under contention.
// Even though they try to pump only the COM messages, any
// messages that have been SENT to the window are also
// dispatched. This can lead to unpredictable reentrancy.
return MS.Win32.UnsafeNativeMethods.WaitForMultipleObjectsEx(waitHandles.Length, waitHandles, waitAll, millisecondsTimeout, false);
}
else
{
return SynchronizationContext.WaitHelper(waitHandles, waitAll, millisecondsTimeout);
}
}
“拥有 SUC”是什么意思?
它似乎代表
SuppressUnmanagedCodeSecurity
属性。请参阅源代码了解WaitForMultipleObjectsEx
///<SecurityNote>
/// Critical as this code performs an elevation.
///</SecurityNote>
[SecurityCritical]
[SuppressUnmanagedCodeSecurity]
[DllImport(ExternDll.Kernel32, EntryPoint="WaitForMultipleObjectsEx", SetLastError = true, CharSet = CharSet.Auto)]
private static extern int IntWaitForMultipleObjectsEx(int nCount, IntPtr[] pHandles, bool bWaitAll, int dwMilliseconds, bool bAlertable);