I Inman Well-Known Member Licensed User Longtime User Jan 12, 2019 #1 In my app I have a For Next loop that is used to copy all files in a particular folder. Since the target location is a URI, I use the method given here to copy the files. And it works correctly too. The problem arises when there are a lot of files to copy. Like there is a user who tried to copy about 3000 files in a folder. He reported that every time he tried, the loop copies a few files and then goes to stay in "not responding" mode. He then force stops it, tries again, copies a few more and then "not responding". I am wondering if this has something to do with the app running out of resources. I have tried the same with like 10 to 50 files and it never had any issues. But apparently with 1000+ files it hangs. So is there a right way to lock and release resources after copying each file?
In my app I have a For Next loop that is used to copy all files in a particular folder. Since the target location is a URI, I use the method given here to copy the files. And it works correctly too. The problem arises when there are a lot of files to copy. Like there is a user who tried to copy about 3000 files in a folder. He reported that every time he tried, the loop copies a few files and then goes to stay in "not responding" mode. He then force stops it, tries again, copies a few more and then "not responding". I am wondering if this has something to do with the app running out of resources. I have tried the same with like 10 to 50 files and it never had any issues. But apparently with 1000+ files it hangs. So is there a right way to lock and release resources after copying each file?
Erel B4X founder Staff member Licensed User Longtime User Jan 13, 2019 #2 The issue is not related to resource management or locks. You need to use File.CopyAsync or Copy2Async to make the copy without blocking the main thread. Upvote 0
The issue is not related to resource management or locks. You need to use File.CopyAsync or Copy2Async to make the copy without blocking the main thread.
I Inman Well-Known Member Licensed User Longtime User Jan 13, 2019 #3 Thanks Erel. I will make this change in the activity's code. Besides activity, I also perform similar copy operation in a service as well using File.Copy2. Since there is no UI thread here, is it necessary to change this Copy2 to Copy2Async? Upvote 0
Thanks Erel. I will make this change in the activity's code. Besides activity, I also perform similar copy operation in a service as well using File.Copy2. Since there is no UI thread here, is it necessary to change this Copy2 to Copy2Async?
Erel B4X founder Staff member Licensed User Longtime User Jan 13, 2019 #4 Yes. It doesn't matter whether the code is in a service or an activity. Upvote 0