How to terminate anonymous threads in Delphi on application close?

前端 未结 3 474
無奈伤痛
無奈伤痛 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:48

    Make your threads watch for some kind of notification from the outside. This could be an event that gets signaled, a message sent to a window owned by the thread, a command sent over a socket that your thread listens to, or whatever other form of communication you find.

    If you determine that this problem is because your threads are so-called "anonymous" threads, then a simple workaround is for you to make them be non-anonymous threads. Put the body of the anonymous function into the Execute method, and pass any captured variables to the thread class via its constructor.

提交回复
热议问题