Index: /trunk/dll/common.c
===================================================================
--- /trunk/dll/common.c	(revision 1569)
+++ /trunk/dll/common.c	(revision 1570)
@@ -150,5 +150,5 @@
   case UM_RESCAN:
     if (fAutoTile &&
-	!fAmClosing && !fNoTileUpdate && !ParentIsDesktop(hwnd, (HWND) 0))
+        !fAmClosing && !fNoTileUpdate && !ParentIsDesktop(hwnd, (HWND) 0))
       PostMsg(WinQueryWindow(hwnd, QW_PARENT), UM_RESCAN, MPVOID, MPVOID);
     return 0;
Index: /trunk/dll/comp.c
===================================================================
--- /trunk/dll/comp.c	(revision 1569)
+++ /trunk/dll/comp.c	(revision 1570)
@@ -76,4 +76,5 @@
   23 Oct 10 GKY Add ForwardslashToBackslash function to streamline code
   29 May 11 SHL Rework >65K records logic - prior fix was not quite right
+  12 Jun 11 GKY Added SleepIfNeeded in the container fill loop
 
 ***********************************************************************/
@@ -1343,4 +1344,5 @@
   APIRET rc;
   static BOOL fDone;
+  ITIMER_DESC itdSleep = { 0 };		// 30 May 11 GKY
 
   if (!str || !*str) {
@@ -1376,4 +1378,5 @@
 		     pffbArray, ulBufBytes, &ulFindCnt, FIL_QUERYEASIZEL);
   if (!rc) {
+    InitITimer(&itdSleep, 500);
     do {
       pffbFile = pffbArray;
@@ -1423,4 +1426,5 @@
       ulFindCnt = FilesToGet;
       rc = xDosFindNext(hDir, pffbArray, ulBufBytes, &ulFindCnt, FIL_QUERYEASIZEL);
+      SleepIfNeeded(&itdSleep, 1);
     } while (!rc);
 
Index: /trunk/dll/dircnrs.c
===================================================================
--- /trunk/dll/dircnrs.c	(revision 1569)
+++ /trunk/dll/dircnrs.c	(revision 1570)
@@ -1412,5 +1412,6 @@
 	  //DosEnterCritSec(); //GKY 11-27-08
 	  dcd->stopflag++;
-	  //DosExitCritSec();
+          //DosExitCritSec();
+          //DbgMsg(pszSrcFile, __LINE__, "WM_RESCAN");
 	  if (!PostMsg(dcd->hwndObject, UM_RESCAN, MPVOID, MPFROMLONG(1L))) {
 	    strcpy(dcd->directory, dcd->previous);
@@ -1468,5 +1469,5 @@
       WinSetDlgItemText(dcd->hwndClient, DIR_SELECTED, s);
       if (hwndStatus &&
-	  dcd->hwndFrame == WinQueryActiveWindow(dcd->hwndParent)) {
+          dcd->hwndFrame == WinQueryActiveWindow(dcd->hwndParent)) {
 	PostMsg(dcd->hwndObject, UM_RESCAN2, MPVOID, MPVOID);
 	if ((fSplitStatus && hwndStatus2) || fMoreButtons) {
@@ -2313,5 +2314,6 @@
 	//DosEnterCritSec(); //GKY 11-27-08
 	dcd->stopflag++;
-	//DosExitCritSec();
+        //DosExitCritSec();
+        //DbgMsg(pszSrcFile, __LINE__, "WM_RESCAN");
 	if (!PostMsg(dcd->hwndObject, UM_RESCAN, MPVOID, MPVOID)) {
 	  //DosEnterCritSec(); //GKY 11-27-08
@@ -2451,5 +2453,6 @@
 	  //DosEnterCritSec(); // GKY 11-27-08
 	  dcd->stopflag++;
-	  //DosExitCritSec();
+          //DosExitCritSec();
+          //DbgMsg(pszSrcFile, __LINE__, "WM_RESCAN");
 	  if (!PostMsg(dcd->hwndObject, UM_RESCAN, MPVOID, MPFROMLONG(1L))) {
 	    strcpy(dcd->directory, dcd->previous);
@@ -2474,6 +2477,4 @@
 	  strcpy(tempname1, dcd->directory);
 	  AddBackslashToPath(tempname1);
-	  //if (tempname1[strlen(tempname1) - 1] != '\\')
-	  //  strcat(tempname1, "\\");
 	  strcat(tempname1, "..");
 	  DosError(FERR_DISABLEHARDERR);
@@ -2484,13 +2485,10 @@
 	      strcpy(dcd->previous, dcd->directory);
 	      strcpy(dcd->directory, tempname2);
-	      //DosEnterCritSec(); // GKY 11-27-08
 	      dcd->stopflag++;
-	      //DosExitCritSec();
+              //DbgMsg(pszSrcFile, __LINE__, "WM_RESCAN");
 	      if (!PostMsg(dcd->hwndObject,
 			   UM_RESCAN, MPVOID, MPFROMLONG(1L))) {
 		strcpy(dcd->directory, dcd->previous);
-		//DosEnterCritSec();// GKY 11-27-08
 		dcd->stopflag--;
-		//DosExitCritSec();
 	      }
 	      else if (*dcd->directory) {
@@ -2516,12 +2514,9 @@
 	    strcpy(dcd->directory, dcd->previous);
 	    strcpy(dcd->previous, tempname);
-	    //DosEnterCritSec(); // GKY 11-27-08
-	    dcd->stopflag++;
-	    //DosExitCritSec();
+	    dcd->stopflag++; ;
+            //DbgMsg(pszSrcFile, __LINE__, "WM_RESCAN");
 	    if (!PostMsg(dcd->hwndObject, UM_RESCAN, MPVOID, MPFROMLONG(1L))) {
 	      strcpy(dcd->directory, dcd->previous);
-	      //DosEnterCritSec(); // GKY 11-27-08
 	      dcd->stopflag--;
-	      //DosExitCritSec();
 	    }
 	    else if (*dcd->directory) {
@@ -2553,12 +2548,9 @@
 	    strcpy(dcd->previous, dcd->directory);
 	    strcpy(dcd->directory, newdir);
-	    //DosEnterCritSec(); //GKY 11-27-08
 	    dcd->stopflag++;
-	    //DosExitCritSec();
+            //DbgMsg(pszSrcFile, __LINE__, "WM_RESCAN");
 	    if (!PostMsg(dcd->hwndObject, UM_RESCAN, MPVOID, MPFROMLONG(1L))) {
 	      strcpy(dcd->directory, dcd->previous);
-	      //DosEnterCritSec(); // GKY 11-27-08
 	      dcd->stopflag--;
-	      //DosExitCritSec();
 	    }
 	    else if (*dcd->directory) {
@@ -3399,12 +3391,9 @@
 		  strcpy(dcd->previous, dcd->directory);
 		  strcpy(dcd->directory, pci->pszFileName);
-		  //DosEnterCritSec();  // GKY 11-27-08
 		  dcd->stopflag++;
-		  //DosExitCritSec();
+                  //DbgMsg(pszSrcFile, __LINE__, "WM_RESCAN");
 		  if (!PostMsg(dcd->hwndObject,
 			       UM_RESCAN, MPVOID, MPFROMLONG(1))) {
-		    //DosEnterCritSec();  // GKY 11-27-08
 		    dcd->stopflag--;
-		    //DosExitCritSec();
 		  }
 		  else if (*dcd->directory) {
@@ -3446,12 +3435,9 @@
 	      }
 	      else {
-		//DosEnterCritSec();  // GKY 11-27-08
 		dcd->stopflag++;
-		//DosExitCritSec();
+                //DbgMsg(pszSrcFile, __LINE__, "WM_RESCAN");
 		if (!PostMsg(dcd->hwndObject,
 			     UM_RESCAN, MPVOID, MPFROMLONG(1L))) {
-		  //DosEnterCritSec(); // GKY 11-27-08
 		  dcd->stopflag--;
-		  //DosExitCritSec();
 		}
 		else if (*dcd->directory) {
Index: /trunk/dll/dirsize.c
===================================================================
--- /trunk/dll/dirsize.c	(revision 1569)
+++ /trunk/dll/dirsize.c	(revision 1570)
@@ -55,4 +55,5 @@
   20 Nov 10 GKY Check that pTmpDir IsValid and recreate if not found; Fixes hangs caused
                 by temp file creation failures.
+  12 Jun 11 GKY Added SleepIfNeeded in the container fill loop
 
 ***********************************************************************/
@@ -96,4 +97,5 @@
 #include "excputil.h"			// xbeginthread
 #include "pathutil.h"                   // AddBackslashToPath
+#include "tmrsvcs.h"
 
 typedef struct
@@ -267,5 +269,7 @@
     PFILEFINDBUF4L pffbFile;
     ULONG x;
-
+    ITIMER_DESC itdSleep = { 0 };		// 30 May 11 GKY
+
+    InitITimer(&itdSleep, 500);
     while (!rc) {
 
@@ -303,4 +307,5 @@
       DosError(FERR_DISABLEHARDERR);
       rc = xDosFindNext(hdir, pffbArray, ulBufBytes, &ulFindCnt, FIL_QUERYEASIZEL);
+      SleepIfNeeded(&itdSleep, 1);
     } // while more found
 
Index: /trunk/dll/filldir.c
===================================================================
--- /trunk/dll/filldir.c	(revision 1569)
+++ /trunk/dll/filldir.c	(revision 1570)
@@ -95,4 +95,7 @@
   30 May 11 GKY Added SleepIfNeeded to DosFind and container load loops to improve WPS responsiveness
   31 May 11 SHL Disable antique debug code in RemoveCnrItems - really speeds up container close
+  12 Jun 11 GKY Added IdleIfNeeded to the container "free" loops to improve system
+                responsiveness when closing containers with large numbers of items
+  12 Jun 11 GKY Replaced SleepIfNeeded with IdleIfNeeded in the container loade loop
 
 ***********************************************************************/
@@ -986,5 +989,5 @@
 		       &ulFindCnt,
 		       FIL_QUERYEASIZEL);
-    //priority_normal();
+    priority_normal();
     pszFileSpec[strlen(pszFileSpec) - 1] = 0;	// Chop off wildcard
     if (!rc) {
@@ -1113,5 +1116,5 @@
 	ulFindCnt = ulFindMax;
 	rc = xDosFindNext(hdir, paffbFound, ulBufBytes, &ulFindCnt, FIL_QUERYEASIZEL);
-	//priority_normal();
+	priority_normal();
 	if (rc)
 	  DosError(FERR_DISABLEHARDERR);
@@ -1130,4 +1133,5 @@
 	  goto Abort;
 
+        InitITimer(&itdSleep, 500);
 	pci = NULL;
 	ullTotalBytes = 0;
@@ -1169,4 +1173,23 @@
 	  pffbFile = (PFILEFINDBUF4L)((PBYTE)pffbFile + sizeof(FILEFINDBUF4L));
 
+          if (!IdleIfNeeded(&itdSleep, 30)) {
+            for (x = x+1; x < cAffbTotal; x++) {
+              ullBytes = FillInRecordFromFFB(hwndCnr, pci, pszFileSpec,
+                                          pffbFile, partial, dcd);
+              pci = (PCNRITEM) pci->rc.preccNextRecord;
+              ullTotalBytes += ullBytes;
+              if (dcd) {
+                dcd->totalfiles = x;
+                dcd->ullTotalBytes = ullTotalBytes;
+              }
+              pffbFile = (PFILEFINDBUF4L)((PBYTE)pffbFile + sizeof(FILEFINDBUF4L));
+              if (pci == NULL) {
+                priority_normal();
+                InitITimer(&itdSleep, 500);
+                break;
+              }
+            }
+          }
+
 	  if (pci == NULL && ulRecsToInsert) {
 	    memset(&ri, 0, sizeof(RECORDINSERT));
@@ -1195,6 +1218,7 @@
 	    }
 	  }
-	  SleepIfNeeded(&itdSleep, 1);
-	}
+	  //SleepIfNeeded(&itdSleep, 1);
+        }
+        priority_normal();
 	if (ok) {
 	  ullReturnBytes += ullTotalBytes;
@@ -1985,7 +2009,15 @@
     FreeCnrItemData(pci);
     pci = pciNext;
-    SleepIfNeeded(&itdSleep, 1);
-  }
-
+    if (!IdleIfNeeded(&itdSleep, 30)) {
+      for (usCount = usCount + 1; pci; usCount++) {
+        pciNext = (PCNRITEM) pci->rc.preccNextRecord;
+        FreeCnrItemData(pci);
+        pci = pciNext;
+      }
+      break;
+    }
+  }
+  priority_normal();
+  DosPostEventSem(CompactSem);
   if (usCount) {
     if (!WinSendMsg(hwnd, CM_FREERECORD, MPFROMP(&pci), MPFROMSHORT(usCount))) {
@@ -2045,6 +2077,15 @@
 	if (remaining && --remaining == 0)
 	  break;
-	SleepIfNeeded(&itdSleep, 1);
-      }
+        if (!IdleIfNeeded(&itdSleep, 30)) {
+          while (pci) {
+            FreeCnrItemData(pci);
+            pci = (PCNRITEM)pci->rc.preccNextRecord;
+            if (remaining && --remaining == 0)
+              break;
+          }
+        }
+      }
+      priority_normal();
+      DosPostEventSem(CompactSem);
     }
   }
Index: /trunk/dll/makelist.c
===================================================================
--- /trunk/dll/makelist.c	(revision 1569)
+++ /trunk/dll/makelist.c	(revision 1570)
@@ -16,4 +16,6 @@
   29 Feb 08 GKY Use xfree where appropriate
   17 Jul 08 SHL Add SetListOwner for Fortify support
+  12 Jun 11 GKY Added IdleIfNeeded to the freelist loop to improve system
+                responsiveness when freeing lists with large numbers of items
 
 ***********************************************************************/
@@ -36,4 +38,5 @@
 #include "wrappers.h"			// xfree
 #include "fortify.h"			// 06 May 08 SHL
+#include "tmrsvcs.h"			// ITIMER_DESC
 
 static PSZ pszSrcFile = __FILE__;
@@ -85,6 +88,8 @@
 {
   UINT x;
-
+  ITIMER_DESC itdSleep = { 0 };		
+           
   if (list) {
+     InitITimer(&itdSleep, 500);
     for (x = 0; list[x]; x++) {
 #ifdef __DEBUG_ALLOC__
@@ -92,4 +97,10 @@
 #endif
       free(list[x]);
+      if (!IdleIfNeeded(&itdSleep, 30)) { 
+        for (x = x + 1; list[x]; x++) {
+          free(list[x]);
+        }
+        break;
+      }
     }
 #ifdef __DEBUG_ALLOC__
@@ -97,6 +108,7 @@
 #endif
     free(list);
-  }
-  DosPostEventSem(CompactSem);
+    priority_normal();
+    DosPostEventSem(CompactSem);
+  }
 }
 
Index: /trunk/dll/tmrsvcs.c
===================================================================
--- /trunk/dll/tmrsvcs.c	(revision 1569)
+++ /trunk/dll/tmrsvcs.c	(revision 1570)
@@ -9,4 +9,6 @@
 
   05 Jan 08 SHL Baseline
+  12 Jun 11 GKY Added IdleIfNeeded to the container/list fill and free loops to improve system
+                responsiveness when dealing with large numbers of items
 
 ***********************************************************************/
@@ -107,3 +109,15 @@
 }
 
-#pragma alloc_text(TMRSVCS,InitITimer,IsITimerExpired,SleepIfNeeded)
+ULONG IdleIfNeeded(ITIMER_DESC *pitd, LONG delta)
+{
+  APIRET rc;
+
+  if (IsITimerExpired(pitd)) {
+    rc = DosSetPriority(PRTYS_THREAD,PRTYC_IDLETIME,delta,0L);
+    InitITimer(pitd, 0);
+    return rc;
+  }
+  return 1;
+}
+
+#pragma alloc_text(TMRSVCS,InitITimer,IsITimerExpired,SleepIfNeeded,IdleIfNeeded)
Index: /trunk/dll/tmrsvcs.h
===================================================================
--- /trunk/dll/tmrsvcs.h	(revision 1569)
+++ /trunk/dll/tmrsvcs.h	(revision 1570)
@@ -30,4 +30,5 @@
 BOOL IsITimerExpired(ITIMER_DESC *pitd);
 VOID SleepIfNeeded(ITIMER_DESC *pitd, UINT sleepTime);
+ULONG IdleIfNeeded(ITIMER_DESC *pitd, LONG delta);
 
 #endif // TMRSVCS_H
Index: /trunk/dll/treecnr.c
===================================================================
--- /trunk/dll/treecnr.c	(revision 1569)
+++ /trunk/dll/treecnr.c	(revision 1570)
@@ -878,5 +878,5 @@
       WinSendMsg(dcd->hwndCnr,
 		 CM_INVALIDATERECORD,
-		 MPVOID, MPFROM2SHORT(0, CMA_ERASE | CMA_REPOSITION));
+                 MPVOID, MPFROM2SHORT(0, CMA_ERASE | CMA_REPOSITION));
       PostMsg(dcd->hwndCnr, UM_RESCAN, MPVOID, MPVOID);
     }
