فهرست منبع

Bug fix: GUI freezes while executing an extension with ShowResultsInMsgBox or CopyResults flags

(cherry picked from commit efe30f95dde962917c5c39ff9df15552d9c2a9e9)

Source commit: 2365acea6ab7015b8b2affe92735b9598bde4ca7
Martin Prikryl 7 سال پیش
والد
کامیت
5faaa196ed
1فایلهای تغییر یافته به همراه12 افزوده شده و 4 حذف شده
  1. 12 4
      source/windows/Tools.cpp

+ 12 - 4
source/windows/Tools.cpp

@@ -366,11 +366,19 @@ static void __fastcall ExecuteProcessAndReadOutput(const
         CloseHandle(PipeWrite);
       }
 
-      char Buffer[4096];
-      DWORD BytesRead;
-      while (ReadFile(PipeRead, Buffer, sizeof(Buffer), &BytesRead, NULL))
+      DWORD BytesAvail;
+      while (PeekNamedPipe(PipeRead, NULL, 0, NULL, &BytesAvail, NULL))
       {
-        Output += UnicodeString(UTF8String(Buffer, BytesRead));
+        if (BytesAvail > 0)
+        {
+          char Buffer[4096];
+          DWORD BytesToRead = std::min(BytesAvail, static_cast<unsigned long>(sizeof(Buffer)));
+          DWORD BytesRead;
+          if (ReadFile(PipeRead, Buffer, BytesToRead, &BytesRead, NULL))
+          {
+            Output += UnicodeString(UTF8String(Buffer, BytesRead));
+          }
+        }
         // Same as in ExecuteShellCheckedAndWait
         Sleep(200);
         Application->ProcessMessages();