Recent

Author Topic: [LAMW] TThread Synchronize and Queue not working  (Read 8353 times)

WayneSherman

  • Full Member
  • ***
  • Posts: 243
Re: [LAMW] TThread Synchronize and Queue not working
« Reply #15 on: December 08, 2020, 05:07:27 pm »
  RunOnUiThread(i) is like an AsyncTask or a pascal thread?, i can execute io operations with out affect the UI?

One use for RunOnUiThread(i) is to allow a background/worker thread to passed data to the UI.  A background thread should not call methods on UI controls directly since they were not designed to be thread safe.  For example, if a worker thread is used to receive data from an HTTP connection, and you want to display the information in the UI, the thread can call RunOnUiThread(i) to execute UI code which displays the data by calling methods on UI controls.

https://developer.android.com/guide/components/processes-and-threads
Quote
Additionally, the Android UI toolkit is not thread-safe. So, you must not manipulate your UI from a worker thread—you must do all manipulation to your user interface from the UI thread. Thus, there are simply two rules to Android's single thread model:

    Do not block the UI thread
    Do not access the Android UI toolkit from outside the UI thread

AsyncTask is a wrapper around a background/worker thread and callback which passes a result to the UI thread.  It can be used in a similar way:
https://developer.android.com/reference/android/os/AsyncTask

But according to the linked page, AsyncTask has bugs and has been deprecated

"AsyncTask was intended to enable proper and easy use of the UI thread. However, the most common use case was for integrating into UI, and that would cause Context leaks, missed callbacks, or crashes on configuration changes. It also has inconsistent behavior on different versions of the platform, swallows exceptions from doInBackground, and does not provide much utility over using Executors directly."

WayneSherman

  • Full Member
  • ***
  • Posts: 243
Re: [LAMW] TThread Synchronize and Queue not working
« Reply #16 on: December 08, 2020, 05:18:14 pm »
RunOnUiThread(i) is like an AsyncTask or a pascal thread?, i can execute io operations with out affect the UI?

Additionally, fpc threads (e.g. TThread) generally work as expected on Android to create and run code in separate threads, except TThread "synchronize" and "queue" methods do not work (they don't work with LAMW, but I don't know if this is a general problem with Android in fpc).

Segator

  • Full Member
  • ***
  • Posts: 168
    • https://github.com/Nenirey
Re: [LAMW] TThread Synchronize and Queue not working
« Reply #17 on: December 10, 2020, 07:22:56 pm »
Quote
But according to the linked page, AsyncTask has bugs and has been deprecated

So, is convenient change from AsyncTask to RunOnUiThread?
i am Reinier, Nenirey and Segator :) https://github.com/Nenirey

 

TinyPortal © 2005-2018