public static hMailServer.IMAPFolder AssertFolderExists(hMailServer.IMAPFolders folders, string folderName) { int timeout = 100; while (timeout > 0) { try { return folders.get_ItemByName(folderName); } catch (Exception) { } timeout--; Thread.Sleep(100); } string error = "Folder could not be found " + folderName; Assert.Fail(error); return null; }