C #: trigger an event from a locked block

I usually heard that it is a good idea to unlock locks before calling event listeners to avoid a dead end. However, since the block lock {}is reentrant over the same thread in C #, is it okay to trigger events from a blocked block, or do I need to make a copy of the corresponding status data and trigger an event outside the block block?

If not, provide an example when it would be a problem to trigger an event from a block lock {}.

thank

+2
source share
3 answers

, lock. , .

, , . , - , , . . (.. Join()) . , , lock, bingo. .

, , lock, "" . lock, .

+9

, , , , - (, ), , ​​ ( , ). , .

, , , . , . , . , ! -, ( , ).

+4

, . - , , .

In general, you want to minimize the time that you are in the lock, to prevent blocking for too long (causing delays), and also to reduce the likelihood that you will have code that could fail during the lock.

+1
source

Source: https://habr.com/ru/post/1776221/


All Articles