Exception weirdness

A

Andy

Hi all,

I'm trying to debug a program I have.

I have a windows service that has a timer which goes off to check for
some files and process them. The event called to handle the Elaspsed
event is as such:

private void ProcessFiles( object sender, ElapsedEventArgs e ) {
string[] files;
int x;

timer.Enabled = false;

files = Directory.GetFiles( DeliveryPath, "*.xml" );

for( int i = 0 ; !Environment.HasShutdownStarted && !IsPaused && i <
files.Length ; i += 1 ) {
ProcessFile( files[ i ] );
x = 1;
}

timer.Enabled = true;
}

private void ProcessFile( string fileName ) {
try {
// Do processing
}
catch( Exception e ) {
// Handle error (do some logging)
}
finally {
// Do some cleanup
}

return;
}

The odd thing is that the exception fires in ProcessFile, all the code
for the handler runs as well as the Finally block.. but the debugger
never goes to the return; line and its as if I hit Continue. The timer
doesn't go off anymore, nor does the loop finish processing. The
process continues to run, but nothing more happens.

Any ideas?
 
S

S. Senthil Kumar

Does your exception handler generate any exception? That would cause
all the problems you described. You won't hit the return statement and
the timer won't go off again because you turn it on only after the loop
completes, which it never will. And if IIRC, the CLR swallows
exceptions that happen on threadpool threads (like yours), so you'd
never notice it either.

Regards
Senthil
 
A

Andy

Senthil,

It didn't seem to be.. but after I added some exception handlers to
methods called within the catch{} block, things seem to be working.

I guess that was my problem.. I expected exceptions in a catch{} block
to be raised, not swallowed somewhere.

Andy
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top