Firemonkey iPad waiting icon

2019-09-02 10:54发布

I've got two tabs on my application. Both of them have a table - one for input and one for output. When the tab for the output table is activated, a process is triggered which analyze the data and populated the output grid.

The output grid takes a few seconds to render and I would like to display some animated icon. I have tried a TImage with a TFloat animation as well as the TAniIndicator. Both of them seems to freeze while the analyze process is running.

1条回答
男人必须洒脱
2楼-- · 2019-09-02 11:19

Sounds like you have single-threaded application. The problem is that one thread can do one "task" at a time.

In the case of single-threaded applications the main thread is responsible for a couple of things:

  • process UI stuff (refreshing, drawing etc.)
  • execute your code i.e. react on control's events like TabXActivate()
  • etc.

So when you execute your Analyze() function the main thread is blocked and thus cannot refresh UI. As a side effect Animations seem to freeze.

I would suggest moving long-running tasks in separate threads. After the task has finished signal the main thread to stop the indicator and continue to receive user input. This way the main IU thread will not be blocked and TAniIndicator will function correctly.

NB: Beware of thread synchronization and thread safety! VCL/FMX components ARE NOT thread-safe. You can find useful information here:

查看更多
登录 后发表回答