B4J Question Force refresh

Discussion in 'B4J Questions' started by ziomorgan, Feb 12, 2015.

  1. ziomorgan

    ziomorgan Member Licensed User

    How can i force refresh label changes while file reading ?
     
  2. Erel

    Erel Administrator Staff Member Licensed User

    It is not so simple. There is no method such as DoEvents in B4J.

    You will need to use CallSubDelayed to break the task to smaller tasks and run them. If you post the relevant code then it will be easier to explain.
     
  3. ziomorgan

    ziomorgan Member Licensed User

    Code:
    Sub SearchFolder(FolderPath As String, sTMPFileName As String)
       
    Try
         
    ' force refresh
         lblStatus.Text = "ELABORO <" & FolderPath & ">"
         
    If File.Exists(FolderPath, "") = True Then
           
    If File.IsDirectory("", FolderPath) Then
             lFolderChecked = lFolderChecked + 
    1
             
    Dim FilesFound As List = File.ListFiles(FolderPath)
             
    If FilesFound.IsInitialized = True Then
               
    If FilesFound.Size > 0 Then
                 
    For i = 0 To FilesFound.Size - 1
                   
    ' force refresh
                   lblStatus.Text = "ELABORO <" & FilesFound.Get(i) & ">"
                   
    If File.IsDirectory(FolderPath, FilesFound.Get(i)) = True Then
                     lFolderChecked = lFolderChecked + 
    1
                     
    Dim sFileFolderName As String = FilesFound.Get(i)
                     
    If sFileFolderName.ToUpperCase.StartsWith(sTMPFileName) AND _
                      sFileFolderName.ToUpperCase.EndsWith(
    ".RDC"Then
                         ExtractEDL(sFileFolderName, sTMPFileName)
                     
    Else
                       SearchFolder(FolderPath & 
    "/" & sFileFolderName, sTMPFileName)
                     
    End If
                   
    Else
                     lFileChecked = lFileChecked + 
    1
                   
    End If
                 
    Next
               
    End If
             
    End If
           
    Else
             lFileChecked = lFileChecked + 
    1
           
    End If
         
    End If
       
    Catch
       
    End Try
    End Sub
    This is the code, below the "force refresh" comment the line where i want force refresh of label
     
    Last edited: Feb 14, 2015
  4. Erel

    Erel Administrator Staff Member Licensed User

    I recommend you to break this code into multiple subs. It will be more readable / maintainable.

    Updating the label in this loop will not work very good as it will probably be updated too fast for the user to be able to see it.

    However what you can try is to take all the code after the 'force refresh comment and put it in another sub. Now use CallSubDelayed to call this sub.
     
  5. ziomorgan

    ziomorgan Member Licensed User

    work fine.
    is it the same for progress bar ?
     
  6. Erel

    Erel Administrator Staff Member Licensed User

    Yes. In order for the UI to be updated the main thread needs to be free to process an internal message queue. When you use CallSubDelayed you send a message to the queue which is later processed. This way you allow the main thread to process other messages between your tasks.
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice