2018-09-04 07:39:47 -07:00
|
|
|
/*
|
|
|
|
* Efl Core Idler examples.
|
|
|
|
*
|
|
|
|
* Here we register callbacks to execute code when the loop is idle.
|
|
|
|
* We also record when we enter or exit the idle state.
|
|
|
|
*
|
|
|
|
* We initiate a timer to exit the idle state and then exit the application.
|
|
|
|
*/
|
|
|
|
|
|
|
|
using System;
|
|
|
|
|
2019-03-26 04:19:13 -07:00
|
|
|
public class Example : Efl.Csharp.Application
|
2018-09-04 07:39:47 -07:00
|
|
|
{
|
2019-06-28 15:46:12 -07:00
|
|
|
protected override void OnInitialize(string[] args)
|
2018-09-04 07:39:47 -07:00
|
|
|
{
|
|
|
|
// Retrieve the application's main loop
|
2018-12-20 07:28:15 -08:00
|
|
|
var mainloop = Efl.App.AppMain;
|
2018-09-04 07:39:47 -07:00
|
|
|
|
|
|
|
// Register to all Idle events
|
2019-09-06 07:01:45 -07:00
|
|
|
mainloop.IdleEnterEvent += (object sender, EventArgs e) => {
|
2018-09-04 07:39:47 -07:00
|
|
|
Console.WriteLine("IDLE ENTER: Entering idle state.");
|
|
|
|
};
|
2019-09-06 07:01:45 -07:00
|
|
|
mainloop.IdleEvent += (object sender, EventArgs e) => {
|
2018-09-04 07:39:47 -07:00
|
|
|
Console.WriteLine("IDLE: Executing idler callback while in idle state.");
|
|
|
|
};
|
2019-09-06 07:01:45 -07:00
|
|
|
mainloop.IdleExitEvent += (object sender, EventArgs e) => {
|
2018-09-04 07:39:47 -07:00
|
|
|
Console.WriteLine("IDLE EXIT: Leaving idle state.");
|
|
|
|
};
|
|
|
|
|
|
|
|
// Use a timer to exit the application
|
2019-03-26 04:19:13 -07:00
|
|
|
var timer = new Efl.LoopTimer(mainloop, 0.02);
|
2019-09-06 07:01:45 -07:00
|
|
|
timer.TimerTickEvent += (object sender, EventArgs e) => {
|
2019-01-18 07:53:55 -08:00
|
|
|
Console.WriteLine("TIMER: timer callback called, exiting.");
|
2019-03-26 04:19:13 -07:00
|
|
|
mainloop.Quit(0);
|
2019-01-18 07:53:55 -08:00
|
|
|
};
|
2019-03-26 04:19:13 -07:00
|
|
|
}
|
2018-09-04 07:39:47 -07:00
|
|
|
|
2019-03-26 04:19:13 -07:00
|
|
|
#if WIN32
|
|
|
|
[STAThreadAttribute()]
|
|
|
|
#endif
|
|
|
|
public static void Main()
|
|
|
|
{
|
|
|
|
var example = new Example();
|
|
|
|
example.Launch();
|
2018-09-04 07:39:47 -07:00
|
|
|
}
|
|
|
|
}
|