Skip to content

Commit 96fad7b

Browse files
committed
Clarify precaution
1 parent 64ac663 commit 96fad7b

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

docs/core/diagnostics/eventsource-collect-and-view-traces.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,10 +280,10 @@ this isn't required. Following is an example `EventListener` implementation that
280280
>
281281
> To mitigate this risk, consider the following precautions:
282282
>
283-
> - **Avoid Complex Operations**: Refrain from performing complex operations within the callback that might acquire additional locks. For example, during some event callbacks, attempting to use File or Console APIs may encounter issues. Instead, you can update an in-memory datastructure or add some information about the event to a queue. If more processing is needed it can be done from a separate thread after the callback has already returned.
283+
> - **Use Queues to Defer Work**: There are a variety of APIs you might want to call in OnEventWritten() that do non-trivial work, for example File IO, Console, or Http. For most events, these APIs work fine, but if you tried to call Console.WriteLine() in an event handler during the initialization of the Console class then it would probably fail. If you don't know whether a given event handler occurs at a time when APIs are safe to call, consider adding some information about the event to an in-memory queue instead. Then, on a separate thread, process items in the queue.
284284
> - **Minimize Lock Duration**: Ensure that any locks acquired within the callback are not held for extended periods.
285285
> - **Use Non-blocking APIs**: Prefer using non-blocking APIs within the callback to avoid potential deadlocks.
286-
> - **Implement Re-entrancy Guard**: Use a re-entrancy guard to prevent infinite recursion. For example:
286+
> - **Implement a Re-entrancy Guard**: Use a re-entrancy guard to prevent infinite recursion. For example:
287287
>
288288
> ```csharp
289289
> [ThreadStatic] private static bool t_insideCallback;

0 commit comments

Comments
 (0)