How to clean up a thread within seconds before killing it?

171 Views Asked by At

I have a utility which will access the database and clean the garbage files. this is a console application which is being called from another application.

I have a thread from the main thread which will do the tasks while the main thread will be in a loop to check if cancel of the utility has been called.

The functions in the thread call a different dll which takes time. Now, is there any way that when I cancel the thread. Even if it is inside the function, it gets notified to stop immediately and rollback any changes done to the database?

My application is a windows based application and is written in c++. I have tried using TerminateThread() function from Windows but the problem is that is does not allow to do clean up on the thread.

0

There are 0 best solutions below