#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region
'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip
Sub Class_Globals
Private Root As B4XView
Private xui As XUI
Dim Thread1 As Thread
Dim Lock1 As Lock
Private LabelCount As Label
End Sub
Public Sub Initialize
' B4XPages.GetManager.LogEvents = True
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("MainPage")
Thread1.Initialise("Thread1")
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Private Sub Button1_Click
Dim args(0) As Object
Lock1.Initialize(True)
Thread1.Name = "B4A Thread 1"
Thread1.Start(Null, "ThreadSub1", args)
End Sub
Sub ThreadSub1
Dim Count As Int
Dim Params(1) As Object
Do While Count < 1000
Count = Count + 1
Params(0) = Count
Dim Ok As Boolean = False
Do Until Ok
' this is because Android seems to lose the run message if the user presses back button
' this way no message will be ignored
Thread1.RunOnGuiThread("Update1", Params)
Ok = Lock1.WaitFor(1000)
Loop
Loop
End Sub
Sub Update1(Count As Int)
LabelCount.Text = "Count " & Count
Lock1.Unlock
End Sub
Sub Thread1_Ended(fail As Boolean, error As String) 'An error or Exception has occurred in the Thread
MsgboxAsync(error, "Thread1 Ended")
End Sub