Update Interface without rainbow wheel from thread.

Hello guys,

So I have the following process :

  1. Create Temporary backup folder;
  2. Move all the data in the Temporary Backup folder;
  3. Create archive of the Temporary Backup folder;
  4. Delete Temporary Backup folder;
  5. Inform the user that the backup was completed.

Now, I used to do all this via thread and timer, recently it seems that this does not work properly anymore.

On the interface I have few controls that I have to update, 3 labels and one progress bar, please note that all the steps are done in the thread.

So what happens, thread starts, it updates the interface controls via the timer, then it moves to step 2 and the progress wheel on the interface freezes , the gay wheel comes and it stays like that until step 4 when the progress wheel unfreezes and it starts to update the interface again.

I did tried this via the Taks example but it`s even worst and slower fo big No for Task part.

Now, step 2 is using native Xojo code, step3 is using the shell in a method to create that, step 4 native code . so I don’t see why the whole interface it freezes and not updated, it`s like the thread freezes .

Any other ways ?

OS : macOS 10.13.2 (17C205)
Xojo : XOJO2017R3

Thanks.

What is that ?

while not a politically correct description by a long ways… perhaps he is referring to the rainbow wheel that appears when the system is busy?

Depending on how you’re moving your data, Xojo can easily lock up as it waits for the action to occur. Eg moving a file from a to b takes 5 seconds to do, Xojo and all threads will lock until that is done.

All your tasks appear to be able to be done using a shell command. Subclass Shell, run the tasks asynchronously and wait for completed or data available. (I did have problems where completed event never fired so i started echoing out something at the end to get data available event.) Then all you need to do in your thread is start the shell, and loop with a sleep waiting for the shell to complete. Update your properties for the main thread to grab on your timers event , and move onto the next step.

If your tasks cannot be done with a shell command, then add helper apps (console app) to perform native Xojo functions.

Also the “gay wheel” is generally referred to as the beachball

Apologies for the naming, I updated the thread, that wheel was not the best choice but indeed it`s the rainbow wheel.

[quote=368872:@Graham Busch]Depending on how you’re moving your data, Xojo can easily lock up as it waits for the action to occur. Eg moving a file from a to b takes 5 seconds to do, Xojo and all threads will lock until that is done.

All your tasks appear to be able to be done using a shell command. Subclass Shell, run the tasks asynchronously and wait for completed or data available. (I did have problems where completed event never fired so i started echoing out something at the end to get data available event.) Then all you need to do in your thread is start the shell, and loop with a sleep waiting for the shell to complete. Update your properties for the main thread to grab on your timers event , and move onto the next step.

If your tasks cannot be done with a shell command, then add helper apps (console app) to perform native Xojo functions.[/quote]

Thanks Graham,

So it seems that by doing properly the Task version works more smooth than the Thread + Timer, in this case all works ok now except the Shell part , so I guess I will have to adapt that part .

In my case I do :

Function BackupF(BackupFolder As FolderItem, DestFolder As FolderItem) As Boolean
		  Dim CurDte As  New Date
		  Dim CurDteString As String
		  Dim s As New Shell
		  Dim cmd As String
		  Dim result As Boolean
		  Dim ImageName As String
		  Dim BackupFileOutput As String
		  
		  CurDteString = dte.SQLDateTime
		  
		  CurDteString = CurDteString.ReplaceAll("-","")
		  CurDteString = CurDteString.ReplaceAll(":","")
		  CurDteString = CurDteString.ReplaceAll(" ","")
		  
		  
		  
		  ImageName = "Backup_" + CurDteString + ".DMG"
		  
		  Dim ProcessFolder As FolderItem
		  
		  If BackupFolder <> Nil Then
		    
		    BackupFileOutput = DestFolder.Child(ImageName).NativePath
		    
		    
		    cmd = "hdiutil create  -srcFolder " + BackupFolder.NativePath + " " + BackupFileOutput
		    
		    s.Execute cmd
		    
		    If s.ErrorCode = 0 Then
		      result = True
		    Else
		      result = False
		    End If
		  Else
		    result = False
		  End If
		  
		  Return result
		  
		  
		  
		  
		End Function

and on the thread I put :

If mBackupServer.BackupF(TempFolder, mBackupServer.DestFolder) Then
' Go to next step.
End If

Any idea how to optimize this ?

It seems that only this step goes crazy and makes the app unresponsive and transforms the fans in an airplane turbine :stuck_out_tongue:

Thanks.

It is going to lock up xojo on “s.Execute cmd” as this is running synchronously. This might work

[code]s.mode = 1
s.Execute cmd

while s.IsRunning
//Add timeout logic here
me.sleep(100) //sleep for .1 of a second keeping xojo happy. Also assuming me is the thread class
wend

//completed
If s.ErrorCode = 0 Then

[/code]

[quote=368878:@Graham Busch]It is going to lock up xojo on “s.Execute cmd” as this is running synchronously. This might work

[code]s.mode = 1
s.Execute cmd

while s.IsRunning
//Add timeout logic here
me.sleep(100) //sleep for .1 of a second keeping xojo happy. Also assuming me is the thread class
wend

//completed
If s.ErrorCode = 0 Then

[/code][/quote]
Thanks Graham,

It worked perfectly.