Add-Type -Assembly "System.ServiceModel.Internals"
$assembly = [System.AppDomain]::CurrentDomain.GetAssemblies().Where({ $_.GetName().Name -match 'System.ServiceModel.Internals' })
$timer = $assembly.GetTypes().Where({ $_.Name -eq 'IOThreadTimer' })
$timerValue = $timer.GetProperty("SystemTimeResolutionTicks").GetValue($null)
注意,这是您在交互式shell中获得的值,因此不能保证每个进程都获得相同的时间片,但它是通过
// System.Runtime.Interop.UnsafeNativeMethods
public static extern uint GetSystemTimeAdjustment(out int adjustment, out uint increment, out uint adjustmentDisabled);
此外,您的实际命令可能需要不到15毫秒的时间才能返回,这是为了确定线程调度程序在尝试切换任务之前等待的系统时间增量。