private void InternalGetElapsedCpuStatus() { using (SafeThreadHandle currentThread = NativeMethods.GetCurrentThread()) { long cpuCycles = MyStopwatch.CpuCycles; if (currentThread.DangerousGetHandle().ToInt64() == this.timerStartThreadHandle) { if (cpuCycles > this.startCPUcycles) { long num = cpuCycles - this.startCPUcycles; this.elapsedCPU += num; } else { this.elapsedCPU = 0L; this.startCPUcycles = 0L; } } else { this.threadSwitchOccurred = true; this.startCPUcycles = 0L; } } }
public void ResumeMainThread() { var mainThread = Threads[0]; if (mainThread.ThreadState == ThreadState.Wait) { if (SafeNativeMethods.ResumeThread(_mainThread.DangerousGetHandle()) < 0) { throw new Win32Exception(); } } else { throw new NotSupportedException(mainThread.ThreadState.ToString()); } }
public void Start() { if (!this.isRunning) { this.startTimeStamp = MyStopwatch.Timestamp; if (MyStopwatch.CpuTimeIsAvailable) { using (SafeThreadHandle currentThread = NativeMethods.GetCurrentThread()) { this.timerStartThreadHandle = currentThread.DangerousGetHandle().ToInt64(); } this.timerStartCPUID = (int)NativeMethods.GetCurrentProcessorNumber(); this.timerStartCurrentMHz = MyStopwatch.GetCurrentMHz(this.timerStartCPUID); this.timerEndCurrentMHz = this.timerStartCurrentMHz; this.startCPUcycles = MyStopwatch.CpuCycles; } this.isRunning = true; } }
public NativeThread Reopen(ThreadAcccessRights rights = ThreadAcccessRights.All, bool inheritable = false) { var rawHandle = SafeKernelObjHandle.DuplicateHandleLocal(handle.DangerousGetHandle(), (uint)rights, inheritable, SafeKernelObjHandle.DuplicateOptions.None); return(new NativeThread(new SafeThreadHandle(rawHandle))); }