Windows Performance Toolkit
A collection of Microsoft performance monitoring tools that produce in-depth performance profiles of Windows operating systems and applications.
107 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hello,
I'm trying to add the Thread Name to my source code (VS2015, C#, WinForms app) to be displayed in WPA.
Using the code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace AAA
{
static class Program
{
[DllImport("Kernel32", EntryPoint = "GetCurrentThread", ExactSpelling = true)]
public static extern IntPtr GetCurrentWin32Thread();
[DllImport("Kernel32", EntryPoint = "SetThreadDescription", ExactSpelling = true, CharSet = CharSet.Unicode)]
public static extern long SetThreadDescription(IntPtr thHandle, [MarshalAs(UnmanagedType.LPWStr)] string name);
static void SetNativeThName(string sThName)
{
try
{
IntPtr thH = GetCurrentWin32Thread();
long res = SetThreadDescription(thH, sThName);
}
catch (Exception ex)
{
var hr = ex.HResult;
}
}
/// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
SetNativeThName("MyMainThUI");
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
MyFinMain();
Application.Run(new Form1());
}
static public void MyFinMain()
{
Thread.Sleep(10);
}
}
}
I get only the Thread names in the SystemActivity.Threads Lifetimes but not under the CPU precise - Utilization by Process, Thread, Stack
Thanks,
Razvan