 <p>The best way is to use a try/finally block</p> <pre><code>try { this.running = true; ... } finally { this.running = false; } </code></pre> <p>Real thread locks are only needed if this method is called from multiple threads. Given that it appears to be a paint event handler this is unlikely as controls are affinitized to a single thread.</p>