Click here to Skip to main content
16,021,288 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I need urgently help from you guys. i wanted to create textfile in my c drive. ive search for the code and implemented but unsuccessful inserting the value. The value that i want to insert before its will be removes from my listbox.and every 2 second and after containing 6 data in it, the textfile need to be refresh. here my code:

if (listBox1.Items.Count >= 7)
{
string path = @"C:\data.txt";
StreamWriter sw = new StreamWriter(path);

Thread.Sleep(200);
for (int i = 0; i < listBox1.Items.Count; i++)
{
sw.WriteLine(m_strTagUID);
listBox1.Items.RemoveAt(0);
}
sw.Close();
sw.Dispose();

}
Posted

1 solution

I found your question not clear but if you want to execute something every 2 seconds you need to use a timer , the code you wrote just stop executing the code for 2 seconds.
and for more readable code use this
using (StreamWriter sw = new StreamWriter(path))
{
}
//here the the stream will close and dispose automatically 


hope that i could help
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900