开发者

signal playing on c#

开发者 https://www.devze.com 2023-02-25 01:22 出处:网络
i have some values in txt file and also CVS format like belows, sample# g1    g2 0              5  &nbs

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

sample#   g1     g2

0              5       5

1              6 &nb开发者_运维问答sp;     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?


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();
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号