[TASKMGR] Fix some multi-threaded drawing issues. Brought to you by Joachim Henze...
authorAmine Khaldi <amine.khaldi@reactos.org>
Fri, 3 Jul 2015 17:17:56 +0000 (17:17 +0000)
committerAmine Khaldi <amine.khaldi@reactos.org>
Fri, 3 Jul 2015 17:17:56 +0000 (17:17 +0000)
svn path=/trunk/; revision=68336

reactos/base/applications/taskmgr/perfpage.c
reactos/base/applications/taskmgr/procpage.c
reactos/base/applications/taskmgr/taskmgr.c

index 84b4923..3ceadb5 100644 (file)
@@ -23,6 +23,8 @@
 #include "precomp.h"
 #include <shlwapi.h>
 
+extern BOOL bInMenuLoop;        /* Tells us if we are in the menu loop - from taskmgr.c */
+
 TGraphCtrl PerformancePageCpuUsageHistoryGraph;
 TGraphCtrl PerformancePageMemUsageHistoryGraph;
 
@@ -331,12 +333,14 @@ DWORD WINAPI PerformancePageRefreshThread(void *lpParameter)
     ULONG  TotalThreads;
     ULONG  TotalProcesses;
 
-    WCHAR  Text[260];
-    WCHAR  szMemUsage[256];
-
     MSG    msg;
 
+    WCHAR  Text[260];
+    WCHAR  szMemUsage[256], szCpuUsage[256], szProcesses[256];
+
+    LoadStringW(hInst, IDS_STATUS_CPUUSAGE, szCpuUsage, 256);
     LoadStringW(hInst, IDS_STATUS_MEMUSAGE, szMemUsage, 256);
+    LoadStringW(hInst, IDS_STATUS_PROCESSES, szProcesses, 256);
 
     while (1)
     {
@@ -373,10 +377,12 @@ DWORD WINAPI PerformancePageRefreshThread(void *lpParameter)
                                szChargeLimitFormat,
                                sizeof(szChargeLimitFormat));
 
-            wsprintfW(Text, szMemUsage, szChargeTotalFormat, szChargeLimitFormat,
-                      (CommitChargeLimit ? ((CommitChargeTotal * 100) / CommitChargeLimit) : 0));
-
-            SendMessageW(hStatusWnd, SB_SETTEXT, 2, (LPARAM)Text);
+            if (!bInMenuLoop)
+            {
+                wsprintfW(Text, szMemUsage, szChargeTotalFormat, szChargeLimitFormat,
+                    (CommitChargeLimit ? ((CommitChargeTotal * 100) / CommitChargeLimit) : 0));
+                SendMessageW(hStatusWnd, SB_SETTEXT, 2, (LPARAM)Text);
+            }
 
             /*
              *  Update the kernel memory info
@@ -416,6 +422,11 @@ DWORD WINAPI PerformancePageRefreshThread(void *lpParameter)
             SetWindowTextW(hPerformancePageTotalsThreadCountEdit, Text);
             _ultow(TotalProcesses, Text, 10);
             SetWindowTextW(hPerformancePageTotalsProcessCountEdit, Text);
+            if (!bInMenuLoop)
+            {
+                wsprintfW(Text, szProcesses, TotalProcesses);
+                SendMessageW(hStatusWnd, SB_SETTEXT, 0, (LPARAM)Text);
+            }
 
             /*
              *  Redraw the graphs
@@ -430,6 +441,12 @@ DWORD WINAPI PerformancePageRefreshThread(void *lpParameter)
             if (CpuUsage <= 0 )       CpuUsage = 0;
             if (CpuUsage > 100)       CpuUsage = 100;
 
+            if (!bInMenuLoop)
+            {
+                wsprintfW(Text, szCpuUsage, CpuUsage);
+                SendMessageW(hStatusWnd, SB_SETTEXT, 1, (LPARAM)Text);
+            }
+
             if (TaskManagerSettings.ShowKernelTimes)
             {
                 CpuKernelUsage = PerfDataGetProcessorSystemUsage();
index 8c03117..ead0c73 100644 (file)
@@ -419,38 +419,20 @@ void RefreshProcessPage(void)
 
 DWORD WINAPI ProcessPageRefreshThread(void *lpParameter)
 {
-    ULONG    OldProcessorUsage = 0;
-    ULONG    OldProcessCount = 0;
-    WCHAR    szCpuUsage[256], szProcesses[256];
     MSG      msg;
 
-    LoadStringW(hInst, IDS_STATUS_CPUUSAGE, szCpuUsage, 256);
-    LoadStringW(hInst, IDS_STATUS_PROCESSES, szProcesses, 256);
-
     while (1) {
         /*  Wait for an the event or application close */
         if (GetMessage(&msg, NULL, 0, 0) <= 0)
             return 0;
 
         if (msg.message == WM_TIMER) {
-            WCHAR    text[260];
 
             UpdateProcesses();
 
             if (IsWindowVisible(hProcessPage))
                 InvalidateRect(hProcessPageListCtrl, NULL, FALSE);
 
-            if (OldProcessorUsage != PerfDataGetProcessorUsage()) {
-                OldProcessorUsage = PerfDataGetProcessorUsage();
-                wsprintfW(text, szCpuUsage, OldProcessorUsage);
-                SendMessageW(hStatusWnd, SB_SETTEXT, 1, (LPARAM)text);
-            }
-            if (OldProcessCount != PerfDataGetProcessCount()) {
-                OldProcessCount = PerfDataGetProcessCount();
-                wsprintfW(text, szProcesses, OldProcessCount);
-                SendMessageW(hStatusWnd, SB_SETTEXT, 0, (LPARAM)text);
-            }
-
             ProcessPageUpdate();
         }
     }
index 7639c4f..edd5032 100644 (file)
@@ -952,24 +952,18 @@ void TaskManager_OnExitMenuLoop(HWND hWnd)
 {
     RECT   rc;
     int    nParts[3];
-    WCHAR  text[260];
-    WCHAR  szCpuUsage[256], szProcesses[256];
-
-    LoadStringW(hInst, IDS_STATUS_CPUUSAGE, szCpuUsage, 256);
-    LoadStringW(hInst, IDS_STATUS_PROCESSES, szProcesses, 256);
 
     bInMenuLoop = FALSE;
+
     /* Update the status bar pane sizes */
     GetClientRect(hWnd, &rc);
     nParts[0] = STATUS_SIZE1;
     nParts[1] = STATUS_SIZE2;
     nParts[2] = rc.right;
     SendMessageW(hStatusWnd, SB_SETPARTS, 3, (LPARAM) (LPINT) nParts);
-    SendMessageW(hStatusWnd, SB_SETTEXT, 0, (LPARAM)L"");
-    wsprintfW(text, szCpuUsage, PerfDataGetProcessorUsage());
-    SendMessageW(hStatusWnd, SB_SETTEXT, 1, (LPARAM)text);
-    wsprintfW(text, szProcesses, PerfDataGetProcessCount());
-    SendMessageW(hStatusWnd, SB_SETTEXT, 0, (LPARAM)text);
+
+    /* trigger update of status bar columns and performance page asynchronously */
+    RefreshPerformancePage();
 }
 
 void TaskManager_OnMenuSelect(HWND hWnd, UINT nItemID, UINT nFlags, HMENU hSysMenu)