Thread advice

I have a function that uses a timer to watch a folder, and when pdfs appear does a variety of time consuming operations on them. I want this to operate in the background without arresting the UI. So I started a thread that starts the timer. However, the UI still grinds to a halt. I think the problem is that the timer is actually embedded in the window, and so the main thread is still being invoked. Is that correct? If so, is the solution to make the timer a class and instantiate it within the thread?

The Action event of a Timer object will always run on the main (GUI) thread. That’s a feature :slight_smile:

Why don’t you have a thread that watches the folder and the thread is triggered by the timer every few seconds and then from the folder watching thread trigger the processing thread that processes the PDF’s.

That way the timer will run free, the folder monitor will run in its own thread and the PDF processor will run in its own thread

If you’re using a thread, you don’t need the timer. Sleep the thread for the period you would have used on the timer.

I wasn’t sure if you could do that.

Thanks everyone. I’m going to give the thread/sleep thread approach a try.