Root > How to... > ...enable/disable EurekaLog? > Enabling EurekaLog for background threads

Enabling EurekaLog for background threads

Previous pageReturn to chapter overviewNext page   

Important: as a general rule, you should write your application in a such way that it will behave correctly without EurekaLog on board. This means that if your or 3rd party code throws an exception in a thread - it must be handled in a way that you expect. For example, by showing an error message, canceling action, retrying, etc. Once your application behaves like it is supposed to do - then you add EurekaLog for it. EurekaLog will auto-handle all unhandled exceptions automatically (by hooking few well-known places), and for everything else - you can call EurekaLog from your own handlers when needed. In other words:

Incorrect: your application does not show messages for exceptions in thread and you are adding EurekaLog in hopes to fix this behavior;
Correct: your application correctly handles thread exceptions and you are adding EurekaLog to receive reports about such exceptions.

 

EurekaLog has two states which controls if EurekaLog should be active or not: a global state and a local (per-thread) state.

 

1. A global state is controlled by "Activate EurekaLog" option and it could be changed in run-time with SetEurekaLogState routine. Disabling global state will disable EurekaLog in entire application.
2. A local state is a per-thread state - i.e. each thread has its own local state which is independent from states of other threads. The local state for background threads is controlled by "Default EurekaLog state in new threads" option (the main thread is always activated by default) and it could be changed in run-time with SetEurekaLogStateInThread routine. Disabling local state will disable EurekaLog in the current thread, but will keep it activated in other threads.

 

EurekaLog will be active in a particular thread only if both conditions are true:

1. Global state is enabled (IsEurekaLogActive is True).
2. Local state is enabled (IsEurekaLogActiveInThread is True).

If global state is enabled, but local per-thread state is disabled - then EurekaLog will be disabled (in this thread). If local state is enabled, but global state is disabled - then EurekaLog will be disabled.

 

By default, EurekaLog is active globally and it is enabled for main thread only. Therefore, no additional actions are required for single-threaded applications (apart from adding EurekaLog to your application): because a single-threaded application contains only main thread, and EurekaLog is always enabled for main thread by default.

 

Multi-threaded applications is more complex, as multi-threaded application contains additional threads. EurekaLog should be enabled in a particular thread in order to work. Main thread is always enabled - regardless of EurekaLog's options. However, any background thread is disabled by default. You have to enable EurekaLog for your background threads. This can be done in two ways:

1. Automatic, via options (not recommended);
2. Manual, via code:
a. Using BeginThreadEx/TThreadEx (recommended)

 

 

See also:




Send feedback... Build date: 2024-09-30
Last edited: 2023-07-18
PRIVACY STATEMENT
The documentation team uses the feedback submitted to improve the EurekaLog documentation. We do not use your e-mail address for any other purpose. We will remove your e-mail address from our system after the issue you are reporting has been resolved. While we are working to resolve this issue, we may send you an e-mail message to request more information about your feedback. After the issues have been addressed, we may send you an email message to let you know that your feedback has been addressed.


Permanent link to this article: https://www.eurekalog.com/help/eurekalog/multithreading_enable.php