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 .
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=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