summaryrefslogtreecommitdiff
path: root/reference/csharp/core/src/core_event.cs
blob: 7906f41ebeb5940f7eb37f1dfa81eb2c092bbd3e (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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/*
 * 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.Object)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.AppMain;
        mainloop.SetName("Mainloop");

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

        // This timer will control events fired by the main loop
        var timer = new Efl.LoopTimer(mainloop, 0.1);
        timer.SetName("Timer");
        // To count number of timer triggers
        int tick_count = 0;
        timer.TimerTickEvt += (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.Object)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");
    }
}