Article View: borland.public.cppbuilder.nativeapi
Article #11080Problem with Service Hanging
From: Jt
Date: Wed, 25 Feb 2004 20:42
Date: Wed, 25 Feb 2004 20:42
73 lines
3462 bytes
3462 bytes
I have a service that monitors a directory wating for new files to appear.
Then I use findfirst to see of the file matches the file specification i am
searching for. If it does the file is opened, read and written to Oracle.
The service hangs sporadically. I have added some logging to try and track
donw the problem. The problem seems to be when I try to open the file for
reading, but it doesnt throw an exception it just hangs there. Can someone
please give me some suggestions? I have included some code below from the
execute function and the function that opens and reads the file.
void __fastcall TScanThread::Execute()
{
const TCHAR szDirectory[] = "D:\\Apps\\CDNT\\Verizon"; // directory
const DWORD ExitPollInterval = 5 * 60 * 1000; // milliseconds
HANDLE hChange = FindFirstChangeNotification(
szDirectory, // directory to monitor
FALSE, // don't monitor sub-directories
FILE_NOTIFY_CHANGE_FILE_NAME // notifiy on file rename, create or
delete
);
if( FindNextChangeNotification( hChange ) )
while(!Terminated)
{
DWORD WaitResult = WaitForSingleObject( // enter efficient wait
state
hChange,
ExitPollInterval
);
if( WaitResult == WAIT_OBJECT_0 ) // a file has changed
{
ptr = fopen("d:\\Apps\\CDNT\\Verizon\\Processed\\log.txt", "a");
// Process new file
fprintf(ptr, "Scanning for file %s\n", DateTimeToStr(Now()));
bool goodScan = Scan();
fclose(ptr);
}
else if( WaitResult == WAIT_TIMEOUT ) // timeout has occured
without a change notification
continue; // check StopMonitoring
flag, then continue
else
break; // something unexpected
happened, stop monitoring
if( !FindNextChangeNotification( hChange ) )
break;
}
FindCloseChangeNotification( hChange );
}
void __fastcall TScanThread::Openfile(AnsiString Fname)
{
fprintf(ptr, "Inside Openfile Function %s %s\n", Fname,
DateTimeToStr(Now()));
try
{
this is where it hangs but doesnt throw an exception
TFileStream *OldFile = new TFileStream(Folder, fmOpenRead);
TStAnsiTextStream *TS = new TStAnsiTextStream(OldFile);
fprintf(ptr, "Opening file for reading now %s %s\n", Fname,
DateTimeToStr(Now()));
FileName = ExtractFileName(Fname);
Technical Details
Message-ID:
<403d08c8$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailShow Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 10cc67,f5b18ffe280796bd,start X-Google-Attributes: gid10cc67,public X-Google-ArrivalTime: 2004-02-25 13:10:56 PST From: "Jt" <jtoland@bullseyetelecom.com> Newsgroups: borland.public.cppbuilder.nativeapi Subject: Problem with Service Hanging Date: Wed, 25 Feb 2004 15:42:49 -0500 Lines: 76 Organization: Bullseye X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 NNTP-Posting-Host: 207.148.192.94 Message-ID: <403d08c8$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1077741768 207.148.192.94 (25 Feb 2004 12:42:48 -0800) Path: arc1-ca.pugleaf.net!archiver1.google.com!news2.google.com!news.maxwell.syr.edu!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail