Well, he will not even compile, because you're trying to block the type of value.
Introduce a separate lock variable reference type, e.g.
private static readonly object padlock = new object();
Besides:
If StopBrowserCleaning() is called when there is a cleaning thread (at bedtime), but then StartBrowserCleaning() is called before the first thread will notice that it intended to close, you get two streams.
You might want to consider that there are two variables: one for "means that it is a cleaning stream" and one for "really is scouring flow."
In addition, if you are using a monitor with Wait/Pulse or EventHandle (for example, ManualResetEvent ), you can make your sleep more reactive latency when a stop request will be processed faster.
source share