[Gtk-sharp-list] GLib.Idle CPU problem

Peter Johanson peter at peterjohanson.com
Fri Jan 21 10:36:23 EST 2011


That is the difference with GLib.Idle.

It goes like this:

1) Run your IdleHandler.
2) Process any other events that need processing. This could be
*nothing*
3) "Oh, I'm idle again, guess I'll run any idle handlers" => RUns your
IdleHandler (return to step #1).

Which explains your 50% CPU usage, your idle handler is getting run time
after time after time.

With Application.Idle from Winforms, any code you run in your event
subscribed to Application.Idle doesn't count as "get you out of the idle
state" so it will get executed, then lay dormant until the next time it
goes active then idle again. Glib.Idle is *not* the same, it will keep
executing your callback while idle over and over til false is returned.

-pete

On Fri, Jan 21, 2011 at 05:13:50PM +0200, Iliya Iliev wrote:
> Hi,
> 
> I'm returning true because I misunderstand that if I want my event 
> handler to to be executed every time when application goes in Idle state 
> I should return true.
> 
> So is this true that if even I return false from my event handler this 
> handler will be executed every time when application goes to Idle state?
> 
> 
> 
> On 21.01.2011 17:02, Peter Johanson wrote:
> > Iliya,
> >
> >
> > Are you returning true or false from your OnIdle callback?
> >
> > What are you trying to actually accomplish? Application.Idle occurs
> > *once* when the application is about to enter the idle state. Compare
> > this to GLib.Idle.Add, which will *continuously* run your IdleHandler
> > callback over and over until that callback returns false. (compared to
> > just winforms where the event just fires once when it enters the idle
> > state).
> >
> > -pete
> >
> > On Fri, Jan 21, 2011 at 04:45:34PM +0200, Iliya Iliev wrote:
> >> Hi,
> >>
> >> I'm a newbie in GTK#.
> >> I'm trying to find an alternative to Winforms  Application.Idle event
> >> and I found GLib.Idle.Add(new IdleHandler(OnIdle)).
> >> The problem is when I use it my simple program begins to use 50% CPU.
> >> How to fix this? Or there is another approach to do this ?!?!?
> >>
> >> -- 
> >> Best regards,
> >> Iliya Iliev
> >>
> >> _______________________________________________
> >> Gtk-sharp-list maillist  -  Gtk-sharp-list at lists.ximian.com
> >> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
> >>
> 
> -- 
> Best regards,
> Iliya Iliev
> 
> _______________________________________________
> Gtk-sharp-list maillist  -  Gtk-sharp-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/gtk-sharp-list
> 

-- 



More information about the Gtk-sharp-list mailing list