How to terminate anonymous threads in Delphi on application close?

前端 未结 3 484
無奈伤痛
無奈伤痛 2021-01-02 09:50

I have a Delphi application which spawns 6 anonymous threads upon some TTimer.OnTimer event.

If I close the application from the X button in titlebar Access Violatio

3条回答
  •  没有蜡笔的小新
    2021-01-02 10:38

    To avoid errors using CreateAnonymousThread just set FreeOnTerminate to False before starting it.

    This way you can work with the thread as you usually do without any workaround.

    You can read the documentation that says that CreateAnonymousThread automatically sets FreeOnTerminate to True and this is what is causing the errors when you reference the thread.

提交回复
热议问题