# OnIdle() doesn't always work, how to implement OnTimer()?

**URL:** <https://iplug2.discourse.group/t/onidle-doesnt-always-work-how-to-implement-ontimer/1033>\
**Category:** Uncategorized\
**Created:** [16 November 2025 12:06 UTC](https://iplug2.discourse.group/t/onidle-doesnt-always-work-how-to-implement-ontimer/1033 "2025-11-16T12:06:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alex1](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@Alex1](https://iplug2.discourse.group/u/Alex1)\
**Post date:** [16 November 2025 12:06 UTC](https://iplug2.discourse.group/t/onidle-doesnt-always-work-how-to-implement-ontimer/1033/1 "2025-11-16T12:06:33Z")

</div>

I’ve found out that the workability of the OnIdle() function heavily depends on the implementation of the VST host. Sometimes OnIdle() is not called at all. Everything works with the exception of the OnIdle().

I also tried to make my own timer as follows:

```auto
    mUITimer = iplug::Timer::Create([this](iplug::Timer& t) {
        //my code here
    }, 30); 

```

Unfortunately this code is host-dependent too. If I load the VST plug-in in the host’s constuctor and open the plug-in’s UI later, the Timer doesn’t work. Everything works with the exception of the Timer.

Is there a recommended method to implement an OnTimer() function that doesn’t depend on the host’s quirks?

---

<div class="post-metadata">

**Author:** ![olilarkin](https://yyz2.discourse-cdn.com/free1/user_avatar/iplug2.discourse.group/olilarkin/32/2_2.png) [@olilarkin](https://iplug2.discourse.group/u/olilarkin)\
**Post date:** [16 November 2025 18:05 UTC](https://iplug2.discourse.group/t/onidle-doesnt-always-work-how-to-implement-ontimer/1033/2 "2025-11-16T18:05:21Z")

</div>

OnIdle() is triggered by iPlug2’s own timer. [Code search results · GitHub](https://github.com/search?q=repo%3AiPlug2%2FiPlug2+OnIdle()%3B&type=code)

Curious as to why it wouldn’t trigger

---

<div class="post-metadata">

**Author:** ![Alex1](https://avatars.discourse-cdn.com/v4/letter/a/898d66/32.png) [@Alex1](https://iplug2.discourse.group/u/Alex1)\
**Post date:** [17 November 2025 19:42 UTC](https://iplug2.discourse.group/t/onidle-doesnt-always-work-how-to-implement-ontimer/1033/3 "2025-11-17T19:42:40Z")

</div>

I think I understand the reason of the problem. IPlug2 uses the SetTimer() function to create its own timer (line 233 at IGraphicsWind.cpp). The SetTimer() function succeeds, Windows creates a timer, WM\_TIMER messages are put into the thread’s message queue, but the WM\_TIMER messages are never delivered because the host’s constructor thread never runs GetMessage/DispatchMessage. This is not a problem because I start the plug-in in the invisible mode, so I don’t need the OnIdle() function in that mode.

The problem begins when I open the plug-in’s UI in host’s UI thread. The plug-in is fully functional, but the host’s UI thread cannot dispatch WM\_TIMER for a window created on constructor’s thread and my peak meter doesn’t work.

I tried to create a timer in my custom thread and use it instead of the OnIdle() function. This method solves the original problem, but creates an additional thread synchronization problem, so I abandoned it.

I eventually solved this problem on the host side, but I’m still wondering if there’s a recommended way to make the plug-in timer independent of the host implementation.
