C# Console Application Progress / Update Flower

Sometimes you want to show that action is being worked on in a console application, like a progress bar or an ajax loader image. This can be achieved by a progress / update flower class;

public class ConsoleFlower
{
    public ConsoleFlower() {}

    private int count { get; set; }

    private int rate { get; set; }

    internal void Turn(int p)
    {
        rate = p * 500000;

        if (count < 0 || count > (5 * rate)) count = 0;

        if (count == 0) Write("|");
        else if (count == (1 * rate)) Write("/");
        else if (count == (2 * rate)) Write("-");
        else if (count == (3 * rate)) Write("|");
        else if (count == (4 * rate)) Write("-");
        else if (count == (5 * rate)) Write(@"\");

        count++;
    }

    private void Write(string petal)
    {
        Console.Write(petal);
        Console.SetCursorPosition(Console.CursorLeft - 1, Console.CursorTop);
    }
}

This may not be the most efficient code, but it has very low load and can be called like this;

int Count = 1;

while (Count == 1)
{
    Flower.Turn(5);
}

Changing the number in the line

Flower.Turn(5);

changes the speed at which the flower rotates, the higher the number the slower the speed.

One Comment

  1. [...] with System.Net.Mail.MailMessageC# Convert a String to a GuidC# Get the Next Available Drive LetterC# Console Application Progress / Update FlowerSharePointSharePoint Detecting Edit Page Mode ProgrammaticallyDeleting a WebPart from Gallery Using [...]

Leave a Reply