Useful Examples

Blinking Example

Here is a sample code which blinks the label1 UI in the way like black -> gray -> white -> gray -> black... The great point is that you can implement such a feature without using any field variables and without using any lambda functions. You can implement with just a normal code including one while loop and two for loops only.

using SimonPG.WaitCore;

public partial class Form1 : Form {

    IEnumerable<bool> TestFunc(EventWaiter waiter) {

        while (true) {

            for (var bright = 0; bright < 255; bright += 10) {
                label1.BackColor = Color.FromArgb(bright, bright, bright);
                yield return waiter.Wait(timer1, "Tick");
            }

            for (var bright = 255; bright > 0; bright -= 10) {
                label1.BackColor = Color.FromArgb(bright, bright, bright);
                yield return waiter.Wait(timer1, "Tick");
            }
        }
    }

    void Form1_Load(object sender, EventArgs e) {
        new EventWaiter(TestFunc);
    }
}

Last edited Jan 9, 2011 at 2:10 AM by simon_p_g_soft, version 3

Comments

No comments yet.