Loffen Posted May 12, 2005 Posted May 12, 2005 I got a service running in the background. It checks for xml files in a directory. Whenever a new file is present, the service validates the xml, and if the xml is valid, insert the data into a database. After a while of testing, I figured weird results randomly occur if i stop the service while it's working. This is actually what i expected, so I began a search on the web on how to prevent a service from stopping, before a loop is completed. Maybe it's my english, my way of using search engines or just me, but I could not find anything. Nothing about waiting till a loop is done before terminating the service. I though this was a quite "popular" subject... Any suggestions? Thanks, -- Fredrik Aasgaard Quote Erutangis a si tahw
Loffen Posted May 13, 2005 Author Posted May 13, 2005 OK, this is not exactly what i was looking for, but it works... In the loop of the service, around the critical part, lock the active thread like this: lock(this) { //critical part of loop } Now, when the service attempts to stop, it actually enters the OnStop function, completes all thasks there, but the locked thread will continue to execute till it leaves the lock block. After there this thread also terminates. Hope this helps someone.. -- Fredrik Aasgaard Quote Erutangis a si tahw
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.