7 Replies Latest reply on Oct 14, 2013 2:59 PM by David Miller

    Rho::Timer and unblocking UI

    David Miller

      I'm using a Rho:Timer callback to kick off a lengthy db operation.  I was hoping it would unblock the UI so I could enable a button to stop the lengthy db operation by using a flag in another db table.  The db operation checks this flag during it's processing (every 250 rows of operation) and stops processing if the flag == 1.

       

      However, even though I set the db operation running using the timer callback, the UI is still blocked for the length of the processing.  So the button is not effective (navigation eventually times out).

       

      I have tried using AsyncHttp.get but am advised that cannot initiate a local process asynchronously.  So was advised to take a look at the Timer function.  However, I seem to get the same issue - UI blocked for the length of the db operation.

       

      Does anyone have a solution, on a WM6.5 device, to initiate a lengthy process and unblock the UI so the user can press a button to abort it?  

        • Re: Rho::Timer and unblocking UI
          David Miller

          Unless I need to call the timer for every 250 chunk?

            • Re: Rho::Timer and unblocking UI
              David Miller

              Tried using the Timer.  UI still blocked.

                • Re: Rho::Timer and unblocking UI
                  Kutir Mobility

                  You need to let the server finish its current task before it can process another request from the user; one way you can do this is to do your lengthy process in chunks: - check the flag, exit if aborted - process 25 rows - schedule timer to call this process again in a few milliseconds (you will have to experiment with the numbers to see what works for you) Thanks, Javier Kutir Mobility

                  1 of 1 people found this helpful
                    • Re: Rho::Timer and unblocking UI
                      Jon Tara

                      I don't understand why you think you can't use AsyncHttp.get with a callback. This is the normal way you should do downloads with Rhodes, and it works asynchronously and does not block the UI. Who or what "advised" you not to?

                       

                      You may be getting AsyncHttp confused with threads. Rhodes (at least up to 3.5.1, unsure of 4.0) does not support Ruby threads on Android. It does on iOS, and unsure of other platforms. But AsyncHttp doesn't use Ruby threads - it uses native threads - and works fine on both iOS and Android.

                       

                      So, on iOS you can use blocking network I/O in a thread, which is nice if you have existing code or Ruby libraries that depend on this. But it's not necessary, and normally you should just use AsyncHttp.get with a callback.

                       

                      Did you try it?

                      1 of 1 people found this helpful
                        • Re: Rho::Timer and unblocking UI
                          David Miller

                          Hi Jon

                           

                          See this discussion...

                          AsyncHttp HttpAddRequestHeaders Code 6

                           

                          ...and this excerpt from Pietro...

                          "I think that the main problem in your call is that you want to call a local action with the idea to have it returning asynchronously. I don't think that this can work. Rhodes is not intended to be multithreaded and your code will end up freezing all other activities (and I really think that the Async API is intended to be used to call remote server)."

                           

                          You will also note in the above discussion that I make reference to a webinar by Rob Galvin, which I was following.

                           

                          From your reply, I don't claim not to be able to use AsyncHttp.get with a callback.  The issue is it's not unblocking the UI as per what appears to be represented in the webinar example.  However, I am doing inserts into a db, not downloading a file.

                           

                          I am familiar with iOS coding and understand threading concepts - deeply.  Nevertheless, I am using WM6.5.  However, it seems I have designed my application function to use AsyncHttp.get believing I would achieve the result as depicted in the webinar.  But its use appears only to be valid when requesting a remote document (url), not a local one.

                           

                          When you think about it, that operation seems totally valid.

                           

                          I have since tried to use a Timer callback to achieve what I want - to break the operation of a large amount of data processing.  But I ended up with an internal windows fault, so I gave up for the moment.

                           

                          I still have to resolve the requirement though - break the processing when the user requires it.   

                            • Re: Rho::Timer and unblocking UI
                              Jon Tara

                              OK, I understand. In your scenario, using Rho::Timer or AsyncHttp will both have effectively the same results - they are simply used as a mechanism of sending a callback. In 4.0, you can just use a lambda, BTW, instead of having to involve a controller.

                               

                              I would use a Rho::Timer callback in this case, and process a lot less than 250 rows at a time.

                               

                              Ideally, of course, this should be done on a Ruby thread, if they are supported on your platform.

                               

                              Am I correct that there is no download actually involved here, and that you already have data in some form that you need to insert to the database, or some other kind of pure database manipulation?