B4J Question File.Exists hangs my app momentarily

jmon

Well-Known Member
Licensed User
Longtime User
Hello,

When I check if a folder exists with
B4X:
File.Exists(Dir, "")
if the folder doesn't exist, my app freezes for 5 to 10 seconds.

The folder is on a remote computer.

Is there a way to avoid freezing?

Thanks

Jmon
 

Roycefer

Well-Known Member
Licensed User
Longtime User
Run it in another thread using the Threading library.
B4X:
Sub AppStart(....)
   Dim thr As Thread
   thr.Initialise("thr")
   thr.Start(Me,"CheckForFile",Array(Dir,""))
   Wait For File_Result(Result As Boolean)
   Log("Does it exist? " & Result)
End Sub

Sub CheckForFile(dirObj As Object, fnObj As Object)
   Dim dir As String = dirObj
   Dim fn As String = fnObj
   Dim exists As Boolean = File.Exists(dir,fn)
   CallSubDelayed2(Me, "File_Result", exists)
End Sub

Warning: untested.
 
Upvote 0

jmon

Well-Known Member
Licensed User
Longtime User
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…