示例#1
0
        private ProcessThreadTimes GetThreadTimes()
        {
            ProcessThreadTimes threadTimes = new ProcessThreadTimes();

            SafeThreadHandle threadHandle = null;

            try
            {
                threadHandle = OpenThreadHandle(Interop.THREAD_QUERY_INFORMATION);

                if (!Interop.mincore.GetThreadTimes(threadHandle,
                                                    out threadTimes.create,
                                                    out threadTimes.exit,
                                                    out threadTimes.kernel,
                                                    out threadTimes.user))
                {
                    throw new Win32Exception();
                }
            }
            finally
            {
                CloseThreadHandle(threadHandle);
            }

            return(threadTimes);
        }
示例#2
0
        /// <summary>Gets timing information for the current process.</summary>
        private ProcessThreadTimes GetProcessTimes()
        {
            SafeProcessHandle handle = null;

            try
            {
                handle = GetProcessHandle(Interop.Advapi32.ProcessOptions.PROCESS_QUERY_LIMITED_INFORMATION, false);
                if (handle.IsInvalid)
                {
                    throw new InvalidOperationException(SR.Format(SR.ProcessHasExited, _processId.ToString(CultureInfo.CurrentCulture)));
                }

                ProcessThreadTimes processTimes = new ProcessThreadTimes();
                if (!Interop.Kernel32.GetProcessTimes(handle,
                                                      out processTimes._create, out processTimes._exit,
                                                      out processTimes._kernel, out processTimes._user))
                {
                    throw new Win32Exception();
                }
                return(processTimes);
            }
            finally
            {
                ReleaseProcessHandle(handle);
            }
        }
 /// <summary>Gets timing information for the thread.</summary>
 private ProcessThreadTimes GetThreadTimes()
 {
     using (SafeThreadHandle threadHandle = OpenThreadHandle(Interop.Kernel32.ThreadOptions.THREAD_QUERY_INFORMATION))
     {
         var threadTimes = new ProcessThreadTimes();
         if (!Interop.Kernel32.GetThreadTimes(threadHandle,
                                              out threadTimes._create, out threadTimes._exit,
                                              out threadTimes._kernel, out threadTimes._user))
         {
             throw new Win32Exception();
         }
         return(threadTimes);
     }
 }
 private ProcessThreadTimes GetThreadTimes()
 {
     ProcessThreadTimes times = new ProcessThreadTimes();
     Microsoft.Win32.SafeHandles.SafeThreadHandle handle = null;
     try
     {
         handle = this.OpenThreadHandle(0x40);
         if (!Microsoft.Win32.NativeMethods.GetThreadTimes(handle, out times.create, out times.exit, out times.kernel, out times.user))
         {
             throw new Win32Exception();
         }
     }
     finally
     {
         CloseThreadHandle(handle);
     }
     return times;
 }
示例#5
0
        private ProcessThreadTimes GetThreadTimes()
        {
            ProcessThreadTimes times = new ProcessThreadTimes();

            Microsoft.Win32.SafeHandles.SafeThreadHandle handle = null;
            try
            {
                handle = this.OpenThreadHandle(0x40);
                if (!Microsoft.Win32.NativeMethods.GetThreadTimes(handle, out times.create, out times.exit, out times.kernel, out times.user))
                {
                    throw new Win32Exception();
                }
            }
            finally
            {
                CloseThreadHandle(handle);
            }
            return(times);
        }
示例#6
0
        // -----------------------------
        // ---- PAL layer ends here ----
        // -----------------------------

        /// <summary>Gets timing information for the thread.</summary>
        private ProcessThreadTimes GetThreadTimes()
        {
            using (SafeThreadHandle threadHandle = OpenThreadHandle(Interop.mincore.ThreadOptions.THREAD_QUERY_INFORMATION))
            {
                var threadTimes = new ProcessThreadTimes();
                if (!Interop.mincore.GetThreadTimes(threadHandle,
                    out threadTimes._create, out threadTimes._exit,
                    out threadTimes._kernel, out threadTimes._user))
                {
                    throw new Win32Exception();
                }
                return threadTimes;
            }
        }
        private ProcessThreadTimes GetThreadTimes() {
            ProcessThreadTimes threadTimes = new ProcessThreadTimes();

            SafeThreadHandle threadHandle = null;
            try {
                threadHandle = OpenThreadHandle(NativeMethods.THREAD_QUERY_INFORMATION);

                if (!NativeMethods.GetThreadTimes(threadHandle, 
                    out threadTimes.create, 
                    out threadTimes.exit, 
                    out threadTimes.kernel, 
                    out threadTimes.user)) {
                    throw new Win32Exception();
                }
            }
            finally {
                CloseThreadHandle(threadHandle);
            }

            return threadTimes;
        }
示例#8
0
        /// <summary>Gets timing information for the current process.</summary>
        private ProcessThreadTimes GetProcessTimes()
        {
            SafeProcessHandle handle = null;
            try
            {
                handle = GetProcessHandle(Interop.mincore.ProcessOptions.PROCESS_QUERY_LIMITED_INFORMATION, false);
                if (handle.IsInvalid)
                {
                    throw new InvalidOperationException(SR.Format(SR.ProcessHasExited, _processId.ToString(CultureInfo.CurrentCulture)));
                }

                ProcessThreadTimes processTimes = new ProcessThreadTimes();
                if (!Interop.mincore.GetProcessTimes(handle, 
                    out processTimes._create, out processTimes._exit, 
                    out processTimes._kernel, out processTimes._user))
                {
                    throw new Win32Exception();
                }
                return processTimes;
            }
            finally
            {
                ReleaseProcessHandle(handle);
            }
        }
 private ProcessThreadTimes GetProcessTimes()
 {
     ProcessThreadTimes times = new ProcessThreadTimes();
     Microsoft.Win32.SafeHandles.SafeProcessHandle processHandle = null;
     try
     {
         processHandle = this.GetProcessHandle(0x400, false);
         if (processHandle.IsInvalid)
         {
             throw new InvalidOperationException(SR.GetString("ProcessHasExited", new object[] { this.processId.ToString(CultureInfo.CurrentCulture) }));
         }
         if (!Microsoft.Win32.NativeMethods.GetProcessTimes(processHandle, out times.create, out times.exit, out times.kernel, out times.user))
         {
             throw new Win32Exception();
         }
     }
     finally
     {
         this.ReleaseProcessHandle(processHandle);
     }
     return times;
 }