aboutsummaryrefslogtreecommitdiffstats
path: root/reference/csharp/core/src/core_poll.cs
blob: a05e7b9d68878f3dcac7de375c9560c558209d22 (plain) (blame)
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
/*
 * Efl Core Poll examples.
 *
 * This example sets up poll callbacks for LOW, MEDIUM and HIGH frequency events.
 * We run for 30 seconds and print to stdout to show when each is called.
 * Depending on your system this may not include any LOW frequency polls.
 */

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.GetLoopMain();

        // Register to all Poll events
        mainloop.PollLowEvt += (object sender, EventArgs e) => {
          Console.Write("L");
        };
        mainloop.PollMediumEvt += (object sender, EventArgs e) => {
          Console.Write("M");
        };
        mainloop.PollHighEvt += (object sender, EventArgs e) => {
          Console.Write(".");
        };

        // Use a timer to exit the application
        new efl.Loop_Timer(mainloop, (efl.ILoop_Timer etimer) => {
            // Trigger after 30s
            etimer.SetInterval(30);
            etimer.TickEvt += (object sender, EventArgs e) => {
              Console.WriteLine("\nTIMER: 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();
    }
}