Delphi – How to capture TTHREAD that suddenly destroyed

My Environment: Rad Studio XE4 using C++

I am using TThread to develop a software. Recently, I encountered a problem, namely Days later, TThread was suddenly destroyed.

In TThread, the thread uses the Synchronize() method to change the display of forms (such as TLable). I want to know that this may cause some problems.

I am logging several parts of the thread so that I can find out the cause of the problem. But when I check the log, I can only find that the destructor of TThread is suddenly called.

FreeOnTerminate of TThread Set to true.

The program runs two threads. Only one thread is suddenly destroyed, and the other thread is still working even after the problem occurs.

I am looking for how to solve this The reason for the problem.

when I check the log, I can only find that the destructor of the TThread is suddenly called.

The only way that can happen is:

>If you set the FreeOnTerminate attribute of the thread to true (you are ) And your thread is terminated because its Execute() method exited (because it encountered a return statement, reached the end of its code, or raised an exception you did not catch). To record whether the thread is terminating, You can override its virtual DoTerminate() method, or assign it an OnTerminate event handler.
>If some code outside the thread calls delete on the thread object pointer. To record whether this happens, you must record delete Call.

Given that you set FreeOnTerminate to true, the possible culprit is Execute() exit due to an uncaught exception.

< pre>My Environment: Rad Studio XE4 using C++

I am using TThread to develop a software. Recently, I encountered One problem is that TThread is suddenly destroyed a few days after the program is started.

In TThread, the thread uses the Synchronize() method to change the display of the form (such as TLable). I want to know this may cause some The problem.

I am recording several parts of the thread so that I can find out the cause of the problem. But when I check the log, I can only find that the destructor of TThread is suddenly called.

p>

FreeOnTerminate of TThread is set to true.

The program runs two threads. Only one thread is suddenly destroyed, and the other thread is still working even after the problem occurs.

< p>I am looking for how to solve this type of problem.

when I check the log, I can only find that the destructor of the TThread is suddenly called.

The only way that can happen is:

>If you set the FreeOnTerminate attribute of the thread to true (you are) and your The thread is terminated because its Execute() method exited (because it encountered a return statement, reached the end of its code, or raised an exception you did not catch). To record whether the thread is terminating, you can override it Virtual DoTerminate() method, or assign OnTerminate event handler to it.
>If some code outside the thread calls delete on the thread object pointer. To record whether this happens, you must record the delete call.
> p>

Given that you set FreeOnTerminate to true, the possible culprit is Execute() exit due to an uncaught exception.

WordPress database error: [Table 'yf99682.wp_s6mz6tyggq_comments' doesn't exist]
SELECT SQL_CALC_FOUND_ROWS wp_s6mz6tyggq_comments.comment_ID FROM wp_s6mz6tyggq_comments WHERE ( comment_approved = '1' ) AND comment_post_ID = 3135 ORDER BY wp_s6mz6tyggq_comments.comment_date_gmt ASC, wp_s6mz6tyggq_comments.comment_ID ASC

Leave a Comment

Your email address will not be published.