Sleep Function Needed

I have the following function. When the user hits F3, it invokes this function. At the bottom of the function, there is a while loop based off of the number of files found in a directory. It will process these files (converts them from text to binary and moves them - which are in other classes).

What I need is a sleep function, to stop and wait 30 seconds, then rerun the while loop (actually start from where
bWorking = mapsFinder.FindFile( filePattern ); is.

How can I do this? Thanks!

void CInkView::OnF3loadtextmap()
{
//
CString filePath;
CString txtFileDir;
CString fileExt;
CString filePattern;
CString outFilePath;
CString outSaveDir;

GetDocument()->pLot = new CLot( GetDocument() ); // Create the new Lot object with a pointer to the doc

txtFileDir = GetDocument()->pInit->CamtekOutputDir();
fileExt = "\\*.txt";
filePattern = txtFileDir + fileExt;

outFilePath = GetDocument()->pInit->CamtekToMapDir();
outSaveDir = GetDocument()->pInit->CamtekSaveDir();

CFileFind mapsFinder;
BOOL bWorking;

bWorking = mapsFinder.FindFile( filePattern ); // Check the primary map directory first.
while (bWorking) // Continue while there are more files.
{
bWorking = mapsFinder.FindNextFile();
filePath = mapsFinder.GetFilePath();

GetDocument()->pLot->CamtekToMap(filePath, outFilePath, outSaveDir);

}

}
[1571 byte] By [sanclan] at [2007-11-19 18:28:35]
# 1 Re: Sleep Function Needed
What I need is a sleep function, to stop and wait 30 secondsPerhaps this -
::Sleep (30*1000);
...Is what you are looking for. ;)
Siddhartha at 2007-11-10 23:46:42 >
# 2 Re: Sleep Function Needed
Thank you. My dilemma is putting the code after the While loop and then having it rerun it after the Sleep function.

So,

bWorking = ......

While (bWorking)
{
....
}

Sleep (30*1000);

BUT, then what? I need to rerun this again from where bWorking = ... is.

Thanks!!!

Jeff
sanclan at 2007-11-10 23:47:42 >
# 3 Re: Sleep Function Needed
My dilemma is putting the code after the While loop and then having it rerun it after the Sleep function. Perhaps, you need to put another loop around the lines of code that need to be re-run.

for (unsigned int nCount = 0; nCount < NUMBER_OF_TIMES_TO_RUN; ++nCount)
{
bWorking = ......

while (bWorking)
{
....
}

Sleep (30*1000);
}
Simple. ;)
Siddhartha at 2007-11-10 23:48:46 >
# 4 Re: Sleep Function Needed
Why do you need ::Sleep(..) at all? And why for such long time? I fail to understand why you want to "stuck" your application for 30 seconds? :confused: can you please explain what you are trying to achieve?

PS: looks like it will be wiser to put it all that code in a worker thread.

Cheers
golanshahar at 2007-11-10 23:49:45 >
# 5 Re: Sleep Function Needed
The application will be continuous. It looks at a directory, pulls text files from it, converts them to another format, moves them, waits 30 seconds, does it again. It'll do this 24/7.

Thanks,

Jeff
sanclan at 2007-11-10 23:50:44 >
# 6 Re: Sleep Function Needed
Ahhh, then you need something like a directory watcher! Check out the FindFirstChangeNotification ( http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/findfirstchangenotification.asp") function.

Viggy
MrViggy at 2007-11-10 23:51:48 >
# 7 Re: Sleep Function Needed
The application will be continuous. It looks at a directory, pulls text files from it, converts them to another format, moves them, waits 30 seconds, does it again. It'll do this 24/7.

Thanks,

Jeff

Ok then, now that you explained it:

This code should be in a worker thread, cause you defiantly dont want to block the main thread for such long time.
One more thing, why you are not using the ::ReadDirectoryChangesW(..) (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/fileio/fs/readdirectorychangesw.asp) api ?

Just an idea ;)

/EDIT: Ah MrViggy was faster :D :thumb:

Cheers
golanshahar at 2007-11-10 23:52:52 >
# 8 Re: Sleep Function Needed
Thanks for all of the information. I'll look into both of those. As you can probably see, I am fairly new to Visual C++, I came over from Visual Basic.

I have created the converters, just need to make them robust and harvest these files continuously. I was trying to keep it very simple.

Thanks again!

JEFF
sanclan at 2007-11-10 23:53:53 >
# 9 Re: Sleep Function Needed
No problem! We were all new once! I don't think there's one person that can know everything about MFC and C++. Hence, these forums exist!

Viggy
MrViggy at 2007-11-10 23:54:44 >
# 10 Re: Sleep Function Needed
Perhaps you should also be thinking about using a timer.

P.S. ReadDirectotryChangesW() will only work with Windows XP and Windows 2000, as far as I'm aware.
John E at 2007-11-10 23:55:45 >