Skip to content

Commit f0930a7

Browse files
committed
* Improved performance when refreshing process list
1 parent 31a046d commit f0930a7

File tree

4 files changed

+30
-30
lines changed

4 files changed

+30
-30
lines changed

MemPlus/Business/UTILS/GridViewSort.cs

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ namespace MemPlus.Business.UTILS
1313
internal class GridViewSort
1414
{
1515
#region Properties
16-
1716
/// <summary>
1817
/// Check whether sorting is enabled or not
1918
/// </summary>
@@ -89,11 +88,9 @@ internal static void SetPropertyName(DependencyObject obj, string value)
8988
typeof(GridViewSort),
9089
new UIPropertyMetadata(null)
9190
);
92-
9391
#endregion
9492

9593
#region ColumnHeader
96-
9794
/// <summary>
9895
/// Method that is called when a ColumnHeader object is clicked
9996
/// </summary>
@@ -111,11 +108,9 @@ private static void ColumnHeader_Click(object sender, RoutedEventArgs e)
111108
ApplySort(listView.Items, propertyName);
112109
}
113110
}
114-
115111
#endregion
116112

117113
#region Helpermethods
118-
119114
/// <summary>
120115
/// Get the parent object of a DependencyObject
121116
/// </summary>
@@ -154,7 +149,6 @@ internal static void ApplySort(ICollectionView view, string propertyName)
154149
view.SortDescriptions.Add(new SortDescription(propertyName, direction));
155150
}
156151
}
157-
158152
#endregion
159153
}
160154
}

MemPlus/Business/UTILS/Utils.cs

Lines changed: 27 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Management;
55
using System.Reflection;
66
using System.Security.Principal;
7+
using System.Threading.Tasks;
78
using System.Windows;
89
using MemPlus.Business.EXPORT;
910
using MemPlus.Business.LOG;
@@ -192,7 +193,7 @@ internal static void ExportLogs(LogType? logType, LogController logController)
192193
/// Export all ProcessDetail objects
193194
/// </summary>
194195
/// <param name="logController">The LogController object that can be used to add logs</param>
195-
internal static void ExportProcessDetails(LogController logController)
196+
internal static async void ExportProcessDetails(LogController logController)
196197
{
197198
SaveFileDialog sfd = new SaveFileDialog
198199
{
@@ -206,16 +207,16 @@ internal static void ExportProcessDetails(LogController logController)
206207
{
207208
//Filterindex starts at 1
208209
case 1:
209-
ProcessDetailExporter.ExportText(sfd.FileName, GetProcessDetails(logController));
210+
ProcessDetailExporter.ExportText(sfd.FileName, await GetProcessDetails(logController));
210211
break;
211212
case 2:
212-
ProcessDetailExporter.ExportHtml(sfd.FileName, GetProcessDetails(logController));
213+
ProcessDetailExporter.ExportHtml(sfd.FileName, await GetProcessDetails(logController));
213214
break;
214215
case 3:
215-
ProcessDetailExporter.ExportCsv(sfd.FileName, GetProcessDetails(logController));
216+
ProcessDetailExporter.ExportCsv(sfd.FileName, await GetProcessDetails(logController));
216217
break;
217218
case 4:
218-
ProcessDetailExporter.ExportExcel(sfd.FileName, GetProcessDetails(logController));
219+
ProcessDetailExporter.ExportExcel(sfd.FileName, await GetProcessDetails(logController));
219220
break;
220221
}
221222
MessageBox.Show("All data has been exported!", "MemPlus", MessageBoxButton.OK, MessageBoxImage.Information);
@@ -232,29 +233,34 @@ internal static void ExportProcessDetails(LogController logController)
232233
/// </summary>
233234
/// <param name="logController">The LogController object that can be used to add logs</param>
234235
/// <returns>A list of ProcessDetail objects that are currently available</returns>
235-
internal static List<ProcessDetail> GetProcessDetails(LogController logController)
236+
internal static async Task<List<ProcessDetail>> GetProcessDetails(LogController logController)
236237
{
237238
logController.AddLog(new ProcessLog("Retrieving process details"));
238239
List<ProcessDetail> processDetailsList = new List<ProcessDetail>();
239-
foreach (Process p in Process.GetProcesses())
240+
241+
await Task.Run(() =>
240242
{
241-
try
243+
foreach (Process p in Process.GetProcesses())
242244
{
243-
ProcessDetail pd = new ProcessDetail
245+
try
244246
{
245-
ProcessId = p.Id,
246-
ProcessName = p.ProcessName,
247-
ProcessLocation = p.MainModule.FileName,
248-
MemoryUsage = (p.WorkingSet64 / (1024 * 1024)).ToString("F2") + " MB",
249-
MemoryUsageLong = p.WorkingSet64
250-
};
251-
processDetailsList.Add(pd);
252-
}
253-
catch (Exception ex)
254-
{
255-
logController.AddLog(new ProcessLog(p.ProcessName + ": " + ex.Message));
247+
ProcessDetail pd = new ProcessDetail
248+
{
249+
ProcessId = p.Id,
250+
ProcessName = p.ProcessName,
251+
ProcessLocation = p.MainModule.FileName,
252+
MemoryUsage = (p.WorkingSet64 / (1024 * 1024)).ToString("F2") + " MB",
253+
MemoryUsageLong = p.WorkingSet64
254+
};
255+
processDetailsList.Add(pd);
256+
}
257+
catch (Exception ex)
258+
{
259+
logController.AddLog(new ProcessLog(p.ProcessName + ": " + ex.Message));
260+
}
256261
}
257-
}
262+
});
263+
258264
logController.AddLog(new ProcessLog("Done retrieving process details"));
259265
return processDetailsList;
260266
}

MemPlus/Views/Windows/MainWindow.xaml.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public MainWindow()
5555
_logController = new LogController(600000);
5656
_logController.AddLog(new ApplicationLog("Initializing MainWindow"));
5757

58-
_updateManager = new UpdateManager.Classes.UpdateManager(Assembly.GetExecutingAssembly().GetName().Version, "https://codedead.com/Software/MemPlus/update.xml", "MemPlus", "Information", "Cancel", "Download", "No new version is currently available.");
58+
_updateManager = new UpdateManager.Classes.UpdateManager(Assembly.GetExecutingAssembly().GetName().Version, "https://codedead.com/Software/MemPlus/update.xml", "MemPlus", "Information", "Cancel", "Download", "You are using the latest version!");
5959
_clearingMemory = false;
6060

6161
InitializeComponent();

MemPlus/Views/Windows/ProcessAnalyzerWindow.xaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,11 @@ private void BtnRefresh_OnClick(object sender, RoutedEventArgs e)
122122
/// <summary>
123123
/// Refresh all ProcessDetail objects
124124
/// </summary>
125-
private void RefreshProcessDetails()
125+
private async void RefreshProcessDetails()
126126
{
127127
_logController.AddLog(new ProcessLog("Refreshing process details"));
128128
LsvProcessList.Items.Clear();
129-
foreach (ProcessDetail pd in Utils.GetProcessDetails(_logController))
129+
foreach (ProcessDetail pd in await Utils.GetProcessDetails(_logController))
130130
{
131131
LsvProcessList.Items.Add(pd);
132132
}

0 commit comments

Comments
 (0)