aboutsummaryrefslogtreecommitdiffstats
path: root/reference/csharp/core/src/core_event.cs
blob: 40bbb654f590454f5a25038bdbdce9305d2a2beb (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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * Efl Core Event examples.
 *
 * This example shows the various ways of adding callbacks for standard events.
 * It also demonstrates how to freeze and thaw events on an object.
 */

using System;

public class Example
{
    // Polling callback
    private static void PollCb(object sender, EventArgs e)
    {
        Console.WriteLine("  Poll from {0}", ((efl.IObject)sender).GetName());
    }

#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();
        mainloop.SetName("Mainloop");

        // This event gets triggered continuously
        mainloop.PollHighEvt += PollCb;

        // This timer will control events fired by the main loop
        new efl.Loop_Timer(mainloop, (efl.ILoop_Timer etimer) => {
            etimer.SetName("Timer");
            // Trigger every 100ms
            etimer.SetInterval(0.1);
            // To count number of timer triggers
            int tick_count = 0;
            etimer.TickEvt += (object sender, EventArgs e) => {
                string message = "Tick {0} from {1}: ";
                // Depending on the number of timer ticks, it does a different thing
                switch (tick_count) {
                    case 0:
                        message += "Freezing Mainloop events";
                        mainloop.FreezeEvent();
                        break;
                    case 1:
                        message += "Thawing Mainloop events";
                        mainloop.ThawEvent();
                        break;
                    default:
                        message += "Quitting";
                        mainloop.Quit(new eina.Value(0));
                        break;
                }
                Console.WriteLine(message, tick_count, ((efl.IObject)sender).GetName());
                tick_count++;
            };
        });

        Console.WriteLine("Waiting for Timer to call back...");

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

        // Shutdown EFL
        efl.All.Shutdown();

        Console.WriteLine("Application is over");
    }
}