I am writing a library which writes something into the database for temporary use (use only once) and then gets removed (its strange, but there is a certain implementation necessary for this ). For this I am trying to execute a thread which writes in the data into the database, waits for the page to finish loading and then releases to finish executing, removing the record. I am not sure how to apprach this. One way is to make the thread sleep but then I am risking either not allowing enough time or the thread might still be running after the page has finished doing everything else. Is there a way to tie this into the page thread so I can release my thread right after it finishes? What are some, if any, approaches to something like this? Because this is a library I would much rather not have another programmer call a function at the end of his page code to remove the record; its messy and easily forgotten.
I am writing a library which writes something into the database for temporary use
Share
Unless you want to use threads for some other reason (i.e. educational) consider using Application events for that – you can listen AcquireRequestState and ReleaseRequestState or similar pair depending on your needs and perform your database operations. Check application lifecicle to see all events and order of them.
How to: Create ASP.NET Application-Level Event Handlers