I want to read single line and put it into textbox every 1 second. I managed this code:
private void button1_Click(object sender, EventArgs e)
{
while ((line = file.ReadLine()) != null)
{
timer.Start();
}
}
private void timer1_Tick(object sender, EventArgs e)
{
textBox1.text += line + "\r\n";
}
But the line
is not accessable. I also tried something like this:
private void button1_Click(object sender, EventArgs e)
{
timer.Start();
}
private void timer1_Tick(object sender, EventArgs e)
{
while ((line = file.ReadLine()) != null)
{
textBox1.Text += line + "\r\n";
}
}
But it's ignoring the timer interval. What's more I have no idea how can I stop the timer in both examples. Can you give me a tip what could I do with this?
Edit
Any ideas why this code works good with if
but not with while
?
private void timer1_Tick(object sender, EventArgs e)
{
while ((line1 = file1.ReadLine()) != null)
{
while ((line2 = file2.ReadLine()) != null)
{
try
{
//some code
}
catch
{
//some code
}
finally
{
//some code
}
}
}
timer1.Stop();
}
I want to combine every row from file2
with every row from file1
.