# Multiple instances of VBlankAttachment

**URL:** https://forum.juce.com/t/multiple-instances-of-vblankattachment/57242
**Category:** General JUCE discussion
**Created:** [July 31, 2023, 4:02pm UTC](https://forum.juce.com/t/multiple-instances-of-vblankattachment/57242 "2023-07-31T16:02:19Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![sudara](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.juce.com/sudara/32/8071_2.png) [@sudara](https://forum.juce.com/u/sudara)
#### Post date: [August 1, 2023, 12:16pm UTC](https://forum.juce.com/t/multiple-instances-of-vblankattachment/57242/3 "2023-08-01T12:16:44Z")

</div>

In addition to animation usages, I’ve started (happily) using VBlankAttachment as an alternative to timers in the UI (to trigger repainting of visualizers and other UI that update on parameter changes).

The approach I was using before was using timers to pick up atomics (set by the audio thread on param change), which seems to be the safest approach, as calling [repaint from the audio thread is dubious](https://forum.juce.com/t/repaint-threadsave/46319), [AsyncUpdater isn’t to be used on the audio thread](https://forum.juce.com/t/should-i-use-sliderlistener-for-component-updates-and-valuetree-listener-for-audio-thread-updates/34806/14), and the parameter changed callbacks (like in the apvts) are [again not the best place to be doing things with components](https://forum.juce.com/t/sending-signal-events-from-audio-to-gui-thread/27792/5).

Now, when parameters change, I still set an atomic flag on the component. The component has a VBlank callback looking for that flag. When true, it calls `repaint()`, flagging the component as dirty. The nice part about this is it happens immediately inline with the next paint call (the timer approach sometimes had drawbacks and glitches since the timer fires at unrelated rates to paint calls).

Edit: I’ve also been assigning the VBlankAttachment to be empty/default constructed on `visibilityChanged` to save polling for the atomic when the components aren’t visible.

---

_[View the full topic](https://forum.juce.com/t/multiple-instances-of-vblankattachment/57242)._
