© 2026 Hedgehog Software, LLC
Twitter
GitHub
Discord
System
Light
Dark
More
Communities
Docs
About
Terms
Privacy
Search
Star
Feedback
Setup for Free
C
C#
•
2y ago
Tony Wang
Synchronizing with Monitor
I have found a code snippet that looks like this
:
var signal
= new object
(
)
;
var signalSet
= false
;
/
/ Thread 1
lock
(signal
)
{
while
(
!signalSet
)
{
Monitor
.Wait
(signal
)
;
}
}
/
/ Thread 2
lock
(signal
)
{
signalSet
= true
;
Monitor
.Pulse
(signal
)
;
}
I am confused about the while loop
. What does it accomplish
? Does a simple
"if
" do the same here
?
Found at
:
https://stackoverflow.com/questions/1355398/monitor-vs-waithandle-based-thread-sync
Stack Overflow
Monitor vs WaitHandle based thread sync
I was under the impression
, after reading this article that it is better to use Monitor
/Lock for thread synchronisation as it does not use native resources
Specific quote
(from page 5 of the articl
.
.
.
C#
Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871
Members
View on Discord
Resources
ModelContextProtocol
ModelContextProtocol
MCP Server
Similar Threads
Was this page helpful?
Yes
No
Recent Announcements
Similar Threads
Monitor Signaling
C
C# / help
2y ago
Synchronizing 2 tables's ID between eachother using EntityFramework Core
C
C# / help
2y ago
All Monitor ScreenShot
C
C# / help
2y ago
Distributed Observability with Open Telemetry and Azure Monitor (Application Insights)
C
C# / help
7mo ago