shallowed
April 3rd, 2006, 10:19 AM
I'm reading up on threads and what they can do in my program... but I've ran across something that I'm debating what I should do. So here's the situation...
I'm writing up a Windows Service that looks through folders, adds info into a database about the files contained in the folders and then renames the files based on the ID I insert into the database. Then from here it will copy the renamed files into a backup folder. Since the program is running on a server with multiple processors I figure that running two seperate threads would make it go faster since the two functions are not dependant on eachother. Well, I'm running into the problem of what do I do when a serious error occurs? It would be nice to destroy the thread in the code that is doing the database transactions or backup, but how do I do that? Can it even be done?
What I'm looking at is using This.CurrentThread.Join(). But the MS specification for this method is as clear as mud for this method since this is my first time even threading (says it blocks until thread is done executing, but does that mean it will continue running my code?). There is a thread.abort() function but that will end up throwing an error all the way back up to the service, which would disrupt the service from running any further (if one thread quits it would be nice to keep the other thread alive doing its thing, then just fix the whatever is going on and then pause and resume the service).
Uhm... yeah, it's a pretty long winded explanation but basically those are my thoughts and I'm looking for advice.
I'm writing up a Windows Service that looks through folders, adds info into a database about the files contained in the folders and then renames the files based on the ID I insert into the database. Then from here it will copy the renamed files into a backup folder. Since the program is running on a server with multiple processors I figure that running two seperate threads would make it go faster since the two functions are not dependant on eachother. Well, I'm running into the problem of what do I do when a serious error occurs? It would be nice to destroy the thread in the code that is doing the database transactions or backup, but how do I do that? Can it even be done?
What I'm looking at is using This.CurrentThread.Join(). But the MS specification for this method is as clear as mud for this method since this is my first time even threading (says it blocks until thread is done executing, but does that mean it will continue running my code?). There is a thread.abort() function but that will end up throwing an error all the way back up to the service, which would disrupt the service from running any further (if one thread quits it would be nice to keep the other thread alive doing its thing, then just fix the whatever is going on and then pause and resume the service).
Uhm... yeah, it's a pretty long winded explanation but basically those are my thoughts and I'm looking for advice.