There is a way. At this time the staff finds out something called separation of concepts ( in English ).
Many of the codes posted here that involve graphical interface makes processing within the interface itself. This is wrong. It may seem silly to separate but you have several reasons to do this. I will not go into details. But you've just discovered one of the reasons.
Just because it works does not mean it's right.
To solve this problem, processing must be separated from the interface. The interface should only trigger the processing, ie it should only call a method that processes the files. This method must belong to the other interface-independent class.
Well, it is possible to do a gambiarra within this for
to solve otherwise, but it is a very bad thing to do and even more complicated to do right.
I usually do not like to just provide links but what you've done is a long way from what needs to be done and only when you walk more would you give more help. Other than that I would have to do everything for you.
This question in SO already gives a good indicator of how it could be made with modern techniques. The posted response indicates an MSDN article that really shows the right way to do it.
It may seem complicated, but doing it the right way is not simple.
I can think of other solutions, some without using asynchronicity, but none is simple. Processing data without blocking the UI is not something simple. It has even been simplified by using async
but pausing and resuming does not have a ready way deal with. By default there is a way to cancel the asynchronous process through a token . To consider a token to pause you need to create your own mechanism. Luckily someone at Microsoft thought about it.
Another example using the same technique.
I do not like that solution using another technique but it's an alternative.
In this answer has an idea that does even more than you want.
What made me think that one of the problems you may have is that it is taking a long time to process because each file is being processed individually. Processing in parallel (asynchronicity already helps a lot in this) can increase processing performance in huge quantities. When you process files, the computer is waiting for the storage device to respond, and most of the time it does nothing. That is, the computer has the ability to process multiple simultaneous files.