Android Question How to use a thread in a Service

Alberto Michelis

Well-Known Member
Licensed User
I trying to make my service run in another thread using the Threding lib
I did the following:

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
Sub Service_Create
   Dim args(0) As Object
   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
Sub ThreadSub1
   SQL1.Initialize(File.DirDefaultExternal, "portit.db", True)

  Timer1.Initialize("Timer1", 10000) ' 1000 = 1 second
  Timer1.Enabled = True

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

How can I do it?

Alberto Michelis

Well-Known Member
Licensed User
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.


Well-Known Member
Licensed User
If it works in Release, then it's a known problem of the threading library with debug mode.


Well-Known Member
Licensed User
Yes it is a known behavior of threading lib.

It doesn't work with rapid debugger but it does work with legacy debugger

try it and you won't have this exception : Exception : wrong number of arguments; expected 4, got 0