signal playing on c#

208 Views Asked by At

i have some values in txt file and also CVS format like belows,

sample#   g1     g2
0              5       5
1              6       7
2              10     8
3              6       6
4              11     9
. . . . . .

There are many solutions about show the values. However, i have been trying to play them as live signal. So, when user press the play button, it should start from 0. second values and progress second by second.
Does anybody has a solution on that?

1

There are 1 best solutions below

0
On

This prints the values line by line one per second to the Console. You may update some WinForms or WPF control just as well.

And you would call timer.Start() from your play button.

var timer = new System.Timers.Timer(1000);
// Your CSV reading might happen in here.
List<string> lines = ReadFromCsv();
int lineNumer = 0;
timer.Elapsed += (sender, e) =>
    {
        if (lineNumer >= lines.Count)
        {
            timer.Enabled = false;
        }
        else
        {
            string line = lines[lineNumer++];
            string[] parts = line.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries);
            foreach (string part in parts)
            {
                // Print every part with width 10 left-justified.
                Console.Write("{0,-10}", part);
            }
            Console.WriteLine();
        }
    };
timer.Start();