44using System . Management ;
55using System . Reflection ;
66using System . Security . Principal ;
7+ using System . Threading . Tasks ;
78using System . Windows ;
89using MemPlus . Business . EXPORT ;
910using 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 }
0 commit comments