private static void ForEachCacheGroup(CacheGroupAction action) { // Groups may not always exist on the system. // For more information, visit the following Microsoft Web site: // http://msdn.microsoft.com/library/?url=/workshop/networking/wininet/overview/cache.asp // By default, a URL does not belong to any group. Therefore, that cache may become // empty even when the CacheGroup APIs are not used because the existing URL does not belong to any group. long groupId = 0; IntPtr enumHandle = FindFirstUrlCacheGroup(0, CACHEGROUP_SEARCH_ALL, IntPtr.Zero, 0, ref groupId, IntPtr.Zero); int err = Marshal.GetLastWin32Error(); // If there are no items in the Cache, you are finished. if (enumHandle == IntPtr.Zero) { if (err != ERROR_NO_MORE_ITEMS && err != ERROR_FILE_NOT_FOUND) { ThrowExceptionForLastWin32Error(); } } else { // Loop through Cache Group. for (;;) { action(groupId); // Get the next one. bool returnValue = FindNextUrlCacheGroup(enumHandle, ref groupId, IntPtr.Zero); err = Marshal.GetLastWin32Error(); if (!returnValue) { if (err != ERROR_NO_MORE_ITEMS && err != ERROR_FILE_NOT_FOUND) { ThrowExceptionForLastWin32Error(); } break; } } } // Process group 0. action(0); }
private static void ForEachCacheGroup(CacheGroupAction action) { // Groups may not always exist on the system. // For more information, visit the following Microsoft Web site: // http://msdn.microsoft.com/library/?url=/workshop/networking/wininet/overview/cache.asp // By default, a URL does not belong to any group. Therefore, that cache may become // empty even when the CacheGroup APIs are not used because the existing URL does not belong to any group. long groupId = 0; IntPtr enumHandle = FindFirstUrlCacheGroup(0, CACHEGROUP_SEARCH_ALL, IntPtr.Zero, 0, ref groupId, IntPtr.Zero); int err = Marshal.GetLastWin32Error(); // If there are no items in the Cache, you are finished. if (enumHandle == IntPtr.Zero) { if (err != ERROR_NO_MORE_ITEMS && err != ERROR_FILE_NOT_FOUND) ThrowExceptionForLastWin32Error(); } else { // Loop through Cache Group. for (;;) { action(groupId); // Get the next one. bool returnValue = FindNextUrlCacheGroup(enumHandle, ref groupId, IntPtr.Zero); err = Marshal.GetLastWin32Error(); if (!returnValue) { if (err != ERROR_NO_MORE_ITEMS && err != ERROR_FILE_NOT_FOUND) ThrowExceptionForLastWin32Error(); break; } } } // Process group 0. action(0); }