I trying to make my service run in another thread using the Threding lib
I did the following:
B4X:
Sub Process_Globals
Dim Thread1 As Thread
Dim Lock1 As Lock
Dim end1 As Int
Dim ok As Boolean
Dim msg As String
I move al my Service_Create code to the ThreadSub1 and replace it with the start thread code
B4X:
Sub Service_Create
Thread1.Initialise("Thread1")
Dim args(0) As Object
Lock1.Initialize(True)
Thread1.Name = "B4A Thread 1"
Thread1.Start(Null, "ThreadSub1", args)
End Sub
I initiate a parser, an Sql object and a timer and run the timer_tick
B4X:
Sub ThreadSub1
parser.Initialize
SQL1.Initialize(File.DirDefaultExternal, "portit.db", True)
Timer1.Initialize("Timer1", 10000) ' 1000 = 1 second
Timer1.Enabled = True
Timer1_Tick
End Sub
Sub Thread1_Ended(fail As Boolean, error As String) 'An error or Exception has occurred in the Thread
Msgbox(error, "Thread1 Ended")
End Sub
When I run it I get an inmediate Thead_Ended error:
Exception : wrong number of arguments; expected 4, got 0
I need to read an parse a web page to a Sql db.
I need to do it every 10 seconds and it last about 1 or 2 seconds.
I do it with a service and its timer.
While my app is running and the user is seing, lets say, a list of prices...
When the service is doing this the UI stops to repond, if the user are swiping the list up and down the scroll stops for this period of time and hen goes back again and I dont want this to happen.