diff --git a/App.config b/App.config
index 8186670..6e50766 100644
--- a/App.config
+++ b/App.config
@@ -1,30 +1,34 @@
-
+
+
-
-
-
-
-
-
-
-
-
-
-
- 3
-
-
- 00:00:02
-
-
-
-
-
- True
-
-
- True
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+ 3
+
+
+ 00:00:02
+
+
+
+
+
+ True
+
+
+ True
+
+
+
\ No newline at end of file
diff --git a/ProcessCpuUsageWatcher.cs b/ProcessCpuUsageWatcher.cs
index e9151c0..cc0c4dc 100644
--- a/ProcessCpuUsageWatcher.cs
+++ b/ProcessCpuUsageWatcher.cs
@@ -40,18 +40,18 @@ namespace ProcessCpuUsageStatusWindow
CurrentProcessList = new Dictionary();
// Get the category for process performance info
- _processCategory = PerformanceCounterCategory.GetCategories().FirstOrDefault(category => category.CategoryName == "Process");
+ _processCategory = PerformanceCounterCategory.GetCategories().FirstOrDefault(category => category.CategoryName == "Process V2");
if (_processCategory == null)
return;
// Read the entire category
- InstanceDataCollectionCollection processCategoryData = _processCategory.ReadCategory();
+ var processCategoryData = _processCategory.ReadCategory();
// Get the processor time data
- InstanceDataCollection processorTimeData = processCategoryData["% processor time"];
+ var processorTimeData = processCategoryData["% processor time"];
- if (processorTimeData == null || processorTimeData.Values == null)
+ if (processorTimeData?.Values == null)
return;
// Loop over each instance and add it to the list
@@ -109,15 +109,15 @@ namespace ProcessCpuUsageStatusWindow
private void UpdateCurrentProcessList()
{
// Get a timestamp for the current time that we can use to see if a process was found this check
- DateTime checkStart = DateTime.Now;
+ var checkStart = DateTime.Now;
// Read the entire category
- InstanceDataCollectionCollection processCategoryData = _processCategory.ReadCategory();
+ var processCategoryData = _processCategory.ReadCategory();
// Get the processor time data
- InstanceDataCollection processorTimeData = processCategoryData["% processor time"];
+ var processorTimeData = processCategoryData["% processor time"];
- if (processorTimeData == null || processorTimeData.Values == null)
+ if (processorTimeData?.Values == null)
return;
// Loop over each instance and add it to the list
@@ -127,7 +127,7 @@ namespace ProcessCpuUsageStatusWindow
if (CurrentProcessList.ContainsKey(instanceData.InstanceName))
{
// Get the previous process usage object
- ProcessCpuUsage processCpuUsage = CurrentProcessList[instanceData.InstanceName];
+ var processCpuUsage = CurrentProcessList[instanceData.InstanceName];
// Update the CPU usage with new data
processCpuUsage.UpdateCpuUsage(instanceData, checkStart);
@@ -144,8 +144,8 @@ namespace ProcessCpuUsageStatusWindow
// Build a list of cached processes we haven't found this check
var oldProcessList = (from processCpuUsage in CurrentProcessList
- where processCpuUsage.Value.LastFound != checkStart
- select processCpuUsage.Key).ToList();
+ where processCpuUsage.Value.LastFound != checkStart
+ select processCpuUsage.Key).ToList();
// Loop over the list and remove the old process
foreach (var key in oldProcessList)
@@ -157,4 +157,4 @@ namespace ProcessCpuUsageStatusWindow
#endregion
}
-}
+}
\ No newline at end of file
diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs
index 35ce6fe..168e215 100644
--- a/Properties/Resources.Designer.cs
+++ b/Properties/Resources.Designer.cs
@@ -19,7 +19,7 @@ namespace ProcessCpuUsageStatusWindow.Properties {
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
public class Resources {
@@ -225,7 +225,7 @@ namespace ProcessCpuUsageStatusWindow.Properties {
}
///
- /// Looks up a localized string similar to CPU: {1,4:f1}% - {0}.
+ /// Looks up a localized string similar to CPU: {1,4:f1}% - {0} ({2}).
///
public static string ProcessLine {
get {
diff --git a/Properties/Resources.resx b/Properties/Resources.resx
index f1c025c..985a0af 100644
--- a/Properties/Resources.resx
+++ b/Properties/Resources.resx
@@ -173,7 +173,7 @@
Options
- CPU: {1,4:f1}% - {0}
+ CPU: {1,4:f1}% - {0} ({2})
_Start when Windows starts
diff --git a/Properties/Settings.Designer.cs b/Properties/Settings.Designer.cs
index b75cc97..f0ed91a 100644
--- a/Properties/Settings.Designer.cs
+++ b/Properties/Settings.Designer.cs
@@ -12,7 +12,7 @@ namespace ProcessCpuUsageStatusWindow.Properties {
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
- [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "15.5.0.0")]
+ [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.5.0.0")]
internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase {
private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
diff --git a/WindowSource.cs b/WindowSource.cs
index ba22f24..95a6036 100644
--- a/WindowSource.cs
+++ b/WindowSource.cs
@@ -2,13 +2,10 @@
using FloatingStatusWindowLibrary;
using ProcessCpuUsageStatusWindow.Options;
using ProcessCpuUsageStatusWindow.Properties;
-using Squirrel;
using System;
using System.Collections.Generic;
using System.Linq;
-using System.Net;
using System.Text;
-using System.Threading;
using System.Threading.Tasks;
using System.Windows.Threading;
@@ -117,7 +114,7 @@ namespace ProcessCpuUsageStatusWindow
private static class PredefinedProcessName
{
public const string Total = "_Total";
- public const string Idle = "Idle";
+ public const string Idle = "Idle:0";
}
private void UpdateDisplay(Dictionary currentProcessList)
@@ -125,14 +122,14 @@ namespace ProcessCpuUsageStatusWindow
// Filter the process list to valid ones and exclude the idle and total values
var validProcessList = (currentProcessList.Values.Where(
process =>
- process.UsageValid && process.ProcessName != PredefinedProcessName.Total &&
- process.ProcessName != PredefinedProcessName.Idle)).ToList();
+ process.UsageValid && process.ProcessName != PredefinedProcessName.Total &&
+ process.ProcessName != PredefinedProcessName.Idle)).ToList();
// Calculate the total usage by adding up all the processes we know about
var totalUsage = validProcessList.Sum(process => process.PercentUsage);
// Sort the process list by usage and take only the top few
- var sortedProcessList = (validProcessList.OrderByDescending(process => process.PercentUsage)).Take(Settings.Default.ProcessCount);
+ var sortedProcessList = validProcessList.OrderByDescending(process => process.PercentUsage).Take(Settings.Default.ProcessCount);
// Create a new string builder
var stringBuilder = new StringBuilder();
@@ -146,14 +143,19 @@ namespace ProcessCpuUsageStatusWindow
}
// Loop over all processes in the sorted list
- foreach (ProcessCpuUsage processCpuUsage in sortedProcessList)
+ foreach (var processCpuUsage in sortedProcessList)
{
// Move to the next line if it isn't the first line
if (stringBuilder.Length != 0)
stringBuilder.AppendLine();
+ var colonPosition = processCpuUsage.ProcessName.LastIndexOf(':');
+
+ var processName = colonPosition == -1 ? processCpuUsage.ProcessName : processCpuUsage.ProcessName.Substring(0, colonPosition);
+ var processId = colonPosition == -1 ? string.Empty : processCpuUsage.ProcessName.Substring(colonPosition + 1);
+
// Format the process information into a string to display
- stringBuilder.AppendFormat(Resources.ProcessLine, processCpuUsage.ProcessName, processCpuUsage.PercentUsage);
+ stringBuilder.AppendFormat(Resources.ProcessLine, processName, processCpuUsage.PercentUsage, processId);
}
// Add the footer line (if any)
@@ -170,4 +172,4 @@ namespace ProcessCpuUsageStatusWindow
#endregion
}
-}
+}
\ No newline at end of file