Android Question Service as long running background task - best approach?

Creideiki

Active Member
Licensed User
Longtime User
Hi,

I have an import of an CSV file into a SQL database (some 10000 records). At the moment, it's done in Main and full of DoEvents -> bad thing.

So I tried to put the import code in a Service.

But - the service runs in the same thread as the UI, so I have nothing won. I still have to do something to keep the UI working.

There are some possibilities:
- Use Async methods, wherever possible. That's nice, when it possible.
- Use sleep(0) - see my following question
- Put the long running things in another thread

What are the pros and cons of the different possibilities?

Concerning sleep(0): What are the performance impacts of that? Let's say, I have a calculation, no chance to do async, perhaps some 100000 iterations. What when I sleep(0) every iteration? Every X iterations? Are there criteria I could use?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
and full of DoEvents -> bad thing.
True. Should be fixed.

Use Async methods, wherever possible. That's nice, when it possible.
When isn't it possible?

- Use Async methods, wherever possible. That's nice, when it possible.
- Use sleep(0) - see my following question
- Put the long running things in another thread
A. No reason that it will not be possible.
B. Not relevant.
C. Implemented in A.
 
Upvote 0

Creideiki

Active Member
Licensed User
Longtime User
A. No reason that it will not be possible.
Well... if I have calculations, but no relevant I/O, there's nothing I could do async. But that's not the problem in my case.
B. Not relevant.
Not relevant in sense of performance? It seems so... I tried with 20000 iterations. Nearly no difference with sleep(0) each iteration or every 100 iterations...
C. Implemented in A.
:)
 
Upvote 0
Top