我在 txt 文件中有一些值,还有 CVS 格式,如下所示,
样品# g1 g2
0 5 5
1 6 7
2 10 8
3 6 6
4 11 9
。. . . . .
关于显示值有很多解决方案。但是,我一直在尝试将它们作为实时信号播放。因此,当用户按下播放按钮时,它应该从 0. 秒值开始,并逐秒进行。
有人对此有解决方案吗?
这将每秒将值逐行打印到控制台。您也可以更新一些 WinForms 或 WPF 控件。
你会timer.Start()
从你的播放按钮调用。
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();