summaryrefslogtreecommitdiff
path: root/reference/csharp/core/src/core_idler.cs
blob: e8853e51c019983bb5b2736c52fd6e5805cc776e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/*
 * 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;

public class Example
{
#if WIN32
    [STAThreadAttribute()]
#endif
    public static void Main()
    {
        // Initialize EFL and all UI components
        Efl.All.Init();

        // Retrieve the application's main loop
        var mainloop = Efl.App.AppMain;

        // Register to all Idle events
        mainloop.IdleEnterEvt += (object sender, EventArgs e) => {
          Console.WriteLine("IDLE ENTER: Entering idle state.");
        };
        mainloop.IdleEvt += (object sender, EventArgs e) => {
          Console.WriteLine("IDLE: Executing idler callback while in idle state.");
        };
        mainloop.IdleExitEvt += (object sender, EventArgs e) => {
          Console.WriteLine("IDLE EXIT: Leaving idle state.");
        };

        // Use a timer to exit the application
        var timer = new Efl.LoopTimer(mainloop, (Efl.LoopTimer etimer) => {
            // Trigger after 10ms
            etimer.SetInterval(0.01);
        });
        timer.TickEvt += (object sender, EventArgs e) => {
          Console.WriteLine("TIMER: timer callback called, exiting.");
          mainloop.Quit(new Eina.Value(0));
        };

        // Start the EFL main loop (and the experiment)
        mainloop.Begin();

        // Shutdown EFL
        Efl.All.Shutdown();
    }
}