GTK: cancel timeout

Channel72 picture Channel72 · Aug 14, 2012 · Viewed 8.2k times · Source

GTK allows you to set a timeout with g_timeout_add. Just like g_signal_connect, the g_timeout_add function returns an id representing the timeout. So, is there a way to cancel a timeout using the id? Looking through the documentation, I don't see any way to cancel a timeout event, but I would assume there must be some way, otherwise what is the point of the id value returned by g_timeout_add?

So, is there any way to cancel a timeout event, or is this just something that needs to be handled manually by setting a "cancellation flag" which can be checked within the user-provided timeout handler function?

Answer

Frédéric Hamidi picture Frédéric Hamidi · Aug 14, 2012

There are two ways to remove a callback registered through g_timeout_add():

  • Have the callback function return FALSE,
  • Call g_source_remove() with the identifier returned by g_timeout_add().